Using google API client in android without account manager

I am currently trying to write a task manager in android that syncs with google tasks. The app uses google client API along with AccountManager to communicate with google servers. It runs Android. However, I want to run it under android on Blackberry playbook. Although the .apk file is converted to the Blackberry app, it seems that the AccountManager does not work under the player player as it is not tied to google account. I find it difficult to communicate with google servers without an account manager. I tried to add the account manually in AccountManager but it also throws a security exception. I'm curious if there is another way to log into google services given a username and password (along with an API key to access)? Thanks to

+3


source to share


1 answer


AccountManager and Google Play Services that allow you to go through the OAuth 2.0 authorization flow using your native Android experience (Google APIs only) are only available on Google Experience devices. The Blackberry Playbook Android Emulator is most likely not a Google Experience framework.

So the best way is to implement OAuth 2.0 flow using WebView. This is also the method you need to use for non-Google APIs (Facebook, Microsoft, Salesforce, Dailymotion, ...)

Basically you will have to send your new users to a special URL in the WebView where Google (or another OAuth 2 provider) will ask them to give you access to the requested APIs. Then you will need to extract the authorization code from the url or from the page content after it has been generated and returned by the google auth servers. The last step is to trade this auth code for an update and an access token.

You need to read and understand how the OAuth 2.0 authorization flow for an installed application works: https://developers.google.com/accounts/docs/OAuth2#installed



Step-by-step process for creating OAuth 2.0 with WebView on Android:

  • Redirect users to grant screen url in embedded WebView
  • Use http://localhost

    as redirect URI
  • Register the WebViewClient with the onPageStarted method to catch page changes.
  • Detecting successful / unsuccessful authorization by detecting redirection to http://localhost

    and reading authentication code from WebView url
  • Complete the OAuth 2 flow by replacing the authentication code for the tokens and store those tokens in a local database for later use.

You can find an open source sample that does this on the Onavo GitHub .

+1


source







All Articles