Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The typical OAuth 2.0 flow goes as follows:</p> <ol> <li>Send a request for permission to access the user's data within a certain scope (<a href="https://www.googleapis.com/auth/tasks" rel="nofollow">https://www.googleapis.com/auth/tasks</a>)</li> <li>User gets the authentication screen where they must log in and allow your app to "Manage your tasks"</li> <li>Your app receives an <strong>authorization code</strong> </li> <li>Your app must exchange the authorization code for an <strong>access token</strong> and a <strong>refresh token</strong>. </li> </ol> <p>The access token can be used to make authenticated requests to the users data, but it will expire after a set amount of time. The refresh token never expires (unless the user revokes your app's privileges in their account settings) and can be used to get a new request token.</p> <p>You can see the whole flow here in the <a href="https://developers.google.com/oauthplayground/" rel="nofollow">OAuth2.0 Playground</a>.</p> <p>If you follow the flow correctly and save the two tokens (in a database or file, depending on the platform) then the user should have to see that screen <em>only once</em>. </p> <p>Now the best part: <strong>the Google API Java client library should handle this all for you</strong>. The exact class to use changes depending on which version of the library you use, but you should be setting the place to persist the tokens when creating your service object. For example, with the calendar API:</p> <pre><code>// For this example we're saving the credentials in a file on the system, // rather than a database. FileCredentialStore credentialStore = new FileCredentialStore( new File(System.getProperty("user.home"), ".credentials/calendar.json"), JSON_FACTORY); // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)) .setCredentialStore(credentialStore) // This will store the tokens for you .build(); </code></pre> <p>You can check this out in the <a href="https://code.google.com/p/google-api-java-client/source/browse/calendar-cmdline-sample/src/main/java/com/google/api/services/samples/calendar/cmdline/CalendarSample.java?repo=samples#80" rel="nofollow">calendar-cmdline-sample here</a>. There are <a href="https://code.google.com/p/google-api-java-client/source/browse/" rel="nofollow">plenty of other samples too</a>, to see the authorization flow on App Engine or Android.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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