Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are not using OAuth 2.0 but OAuth 1.0 with HMAC-SHA1 as the signature method. To use OAuth 2.0, you need at least version 1.47.0 of the <a href="http://code.google.com/p/gdata-java-client/" rel="noreferrer">gdata-java-client</a> library and version 1.8.0-beta of the <a href="http://code.google.com/p/google-oauth-java-client/" rel="noreferrer">google-oauth-java-client</a> library.</p> <p>Using the <a href="http://code.google.com/p/google-api-java-client/" rel="noreferrer">google-api-java-client</a> library provides helper classes to deal with Google's OAuth 2.0 implementation. </p> <p>To retrieve OAuth 2.0 credentials, you can use this code snippet:</p> <pre><code>import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl; import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson.JacksonFactory; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.List; public class MyClass { // Retrieve the CLIENT_ID and CLIENT_SECRET from an APIs Console project: // https://code.google.com/apis/console static String CLIENT_ID = "&lt;YOUR_CLIENT_ID&gt;"; static String CLIENT_SECRET = "&lt;YOUR_CLIENT_SECRET&gt;"; // Change the REDIRECT_URI value to your registered redirect URI for web // applications. static String REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"; // Add other requested scopes. static List&lt;String&gt; SCOPES = Arrays.asList("https://docs.google.com/feeds"); /** * Retrieve OAuth 2.0 credentials. * * @return OAuth 2.0 Credential instance. */ static Credential getCredentials() throws IOException { HttpTransport transport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); // Step 1: Authorize --&gt; String authorizationUrl = new GoogleAuthorizationCodeRequestUrl(CLIENT_ID, REDIRECT_URI, SCOPES).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; GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, CLIENT_ID, CLIENT_SECRET, code, REDIRECT_URI).execute(); // End of Step 2 &lt;-- // Build a new GoogleCredential instance and return it. return new GoogleCredential.Builder().setClientSecrets(CLIENT_ID, CLIENT_SECRET) .setJsonFactory(jsonFactory).setTransport(transport).build() .setAccessToken(response.getAccessToken()).setRefreshToken(response.getRefreshToken()); } // … } </code></pre> <p>Once you have the OAuth 2.0 credential, you can authorize a service object as follow:</p> <pre><code>// ... import com.google.api.client.auth.oauth2.Credential; import com.google.gdata.client.docs.DocsService; import com.google.gdata.data.docs.DocumentListEntry; import com.google.gdata.data.docs.DocumentListFeed; import com.google.gdata.util.ServiceException; // ... import java.io.IOException; import java.net.URL; // ... public class MyClass { // … /** * Print document entries using the provided authorized DocsService. * * @param credential OAuth 2.0 credential to use to authorize the requests. * @throws IOException * @throws ServiceException */ static void printDocuments(Credential credential) throws IOException, ServiceException { // Instantiate and authorize a new DocsService object. DocsService service = new DocsService("&lt;YOUR_APPLICATION_NAME&gt;"); service.setOAuth2Credentials(credential); // Send a request to the Documents List API to retrieve document entries. URL feedUri = new URL("https://docs.google.com/feeds/default/private/full/"); DocumentListFeed feed = service.getFeed(feedUri, DocumentListFeed.class); for (DocumentListEntry entry : feed.getEntries()) { System.out.println("Title: " + entry.getTitle().getPlainText()); } } // ... } </code></pre> <p>The <code>CLIENT_ID</code>, <code>CLIENT_SECRET</code> can be retrieved from the <a href="https://code.google.com/apis/console" rel="noreferrer">APIs Console</a> and the <code>REDIRECT_URI</code> must match one that has been registered with your API Project.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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