Pixelated Words

OAuth 2.0 for Android Applications

with 5 comments

This post is meant for applications that want to use OAuth 2 and are able to use the Android AccountManager.  The  Android AccountManager gives you access to a registry of the user’s online accounts.

Your application needs to prompt the user with a list the available accounts by calling AccountManager#getAccountsByType(String) and allow the user to select their Google account. Once an Account is selected by the user, your application can ask the user for permission to access their data. If the user approves, Google will send your application an access token.

Getting a user’s permission:

Calling AccountManager#getAuthToken will prompt the user for permission to access their data. You need to pass getAuthToken a string containing the required OAuth scopes using the following syntax: oauth2:scope.

For example, if you want to use the Buzz scope, you will pass the string “oauth2:https://www.googleapis.com/auth/buzz“ to getAuthToken.

Example Code:

Written by Chirag

May 21st, 2011 at 12:07 pm

Posted in 2011,android