Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you need multiple OAuth 2.0 scopes, <a href="http://code.google.com/p/google-api-java-client/wiki/OAuth2#Android" rel="nofollow noreferrer">use a space-separated list</a>.</p> <pre><code>oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.userinfo </code></pre> <p>You asked for sample code, so have a look at the <a href="https://github.com/mendhak/googledocs-upload-sample" rel="nofollow noreferrer">Google Docs Upload Sample</a> application, and in this application have look at the authentication flow done in <a href="https://github.com/mendhak/googledocs-upload-sample/blob/master/src/com/mendhak/example/PureJavaUploadActivity.java" rel="nofollow noreferrer">this sample Android screen</a> (ignore that it's about Google Docs, it still authorizes first). You can get the whole application and run it in an emulator with Google APIs present or run it on your phone. The authorization workflow starts with the buttonAuthorize click, Authorize() and you are specifically interested in this method:</p> <pre><code>private void gotAccount(Account account) { Bundle options = new Bundle(); accountManager.getAuthToken( account, // Account retrieved using getAccountsByType() "oauth2:https://www.googleapis.com/auth/userinfo.email oauth2:https://www.googleapis.com/auth/userinfo.userinfo", // Auth scope //"writely", // Auth scope, doesn't work :( options, // Authenticator-specific options this, // Your activity new OnTokenAcquired(), // Callback called when a token is successfully acquired null); // Callback called if an error occurs } </code></pre> <p>The user gets this access request screen:</p> <p><img src="https://i.stack.imgur.com/Y40uP.png" alt="enter image description here"></p> <p>Note that this is using the 'local' OAuth2 mechanism, not opening a web browser, but using the authentication provided when you first activated the Android phone. </p> <p>Also note that the user sees the full URL of the scope instead of a friendly name, I <a href="https://stackoverflow.com/questions/9654633/where-is-the-android-authorization-token-type-alias-list-for-google-apis">haven't</a> found a way around this and if you do find out it would be great if you could share the answer. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload