Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to configure an authorized service object using Google OAuth 2.0
    primarykey
    data
    text
    <p>On the following link there is code which should access the Google Calendar api using OAuth 2.0. Unfortunately it uses the Draft 10 Client Library which is apparently deprecated.</p> <p><a href="https://developers.google.com/google-apps/calendar/instantiate" rel="nofollow">https://developers.google.com/google-apps/calendar/instantiate</a></p> <p>The latest Client Library is google-api-java-client-1.12.0-beta. From what I can make out things have changed a lot since the Draft 10 Client Library and I can't work out how to rewrite this code for the current Client Library.</p> <p>The deprecated code is shown below.</p> <pre><code>import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson.JacksonFactory; import com.google.api.services.calendar.Calendar; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; ... public void setUp() throws IOException { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); // The clientId and clientSecret are copied from the API Access tab on // the Google APIs Console String clientId = "YOUR_CLIENT_ID"; String clientSecret = "YOUR_CLIENT_SECRET"; // Or your redirect URL for web based applications. String redirectUrl = "urn:ietf:wg:oauth:2.0:oob"; String scope = "https://www.googleapis.com/auth/calendar"; // Step 1: Authorize --&gt; String authorizationUrl = new GoogleAuthorizationRequestUrl(clientId, redirectUrl, scope) .build(); // Point or redirect your user to the authorizationUrl. System.out.println("Go to the following link in your browser:"); System.out.println(authorizationUrl); // Read the authorization code from the standard input stream. BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is the authorization code?"); String code = in.readLine(); // End of Step 1 &lt;-- // Step 2: Exchange --&gt; AccessTokenResponse response = new GoogleAuthorizationCodeGrant(httpTransport, jsonFactory, clientId, clientSecret, code, redirectUrl).execute(); // End of Step 2 &lt;-- GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource( response.accessToken, httpTransport, jsonFactory, clientId, clientSecret, response.refreshToken); Calendar service = new Calendar(httpTransport, accessProtectedResource, jsonFactory); service.setApplicationName("YOUR_APPLICATION_NAME"); ... } ... </code></pre> <p>Can anyone tell how to rewrite this code so it works with the current Client Library?</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.
    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