I am getting Invalid Scope error

1,266 views
Skip to first unread message

Neha Chandra

unread,
Aug 1, 2011, 6:26:31 AM8/1/11
to google-app...@googlegroups.com
package com.google.api.client.sample.docs.v3;

import com.google.api.client.auth.oauth.OAuthCredentialsResponse;
import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthParameters;
import com.google.api.client.googleapis.auth.authsub.AuthSubHelper;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthAuthorizeTemporaryTokenUrl;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetAccessToken;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetTemporaryToken;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.javanet.NetHttpTransport;
import com.google.api.client.sample.docs.v3.model.DocsUrl;


import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.net.URI;


public class Auth {

  private static final String APP_NAME ="Google Documents List Data API Java Client Sample";

  private static OAuthHmacSigner signer;

  private static OAuthCredentialsResponse credentials;

  static void authorize(HttpTransport transport) throws Exception {
    // callback server
    LoginCallbackServer callbackServer = null;
    String verifier = null;
    String tempToken = null;
    try {
      
      callbackServer = new LoginCallbackServer();
         callbackServer.start();
           // temporary token
      GoogleOAuthGetTemporaryToken temporaryToken =new GoogleOAuthGetTemporaryToken();
          signer = new OAuthHmacSigner();
         signer.clientSharedSecret = "anonymous";
          temporaryToken.signer = signer;
      temporaryToken.consumerKey = "anonymous";
      temporaryToken.scope ="https://apps-apis.google.com/a/feeds/user/2.0";
          temporaryToken.displayName = APP_NAME;
        temporaryToken.callback = callbackServer.getCallbackUrl();
      System.out.println("temporaryToken.callback: "+temporaryToken.callback);
      OAuthCredentialsResponse tempCredentials = temporaryToken.execute();
          signer.tokenSharedSecret = tempCredentials.tokenSecret;
          // authorization URL
      GoogleOAuthAuthorizeTemporaryTokenUrl authorizeUrl =
          new GoogleOAuthAuthorizeTemporaryTokenUrl();
           authorizeUrl.temporaryToken = tempToken = tempCredentials.token;
      String authorizationUrl = authorizeUrl.build();
      System.out.println("Go to this authorizationUrl: " + authorizationUrl);
      // launch in browser
      boolean browsed = false;
         if (Desktop.isDesktopSupported()) {
         Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Action.BROWSE)) {
          desktop.browse(URI.create(authorizationUrl));
          browsed = true;
        }
      }
      if (!browsed) {
        String browser = "google-chrome";
            Runtime.getRuntime().exec(new String[] {browser, authorizationUrl});
      }
      verifier = callbackServer.waitForVerifier(tempToken);
       } finally {
      if (callbackServer != null) {
        callbackServer.stop();
      }
    }
    GoogleOAuthGetAccessToken accessToken = new GoogleOAuthGetAccessToken();
    accessToken.temporaryToken = tempToken;
    accessToken.signer = signer;
    accessToken.consumerKey = "in.gappsdemo.in";
    accessToken.verifier = verifier;
    credentials = accessToken.execute();
    signer.tokenSharedSecret = credentials.tokenSecret;
    createOAuthParameters().signRequestsUsingAuthorizationHeader(transport);
  }

  static void revoke() {
    if (credentials != null) {
      try {
        GoogleOAuthGetAccessToken.revokeAccessToken(createOAuthParameters());
      } catch (Exception e) {
        e.printStackTrace(System.err);
      }
    }
  }

  private static OAuthParameters createOAuthParameters() {
    OAuthParameters authorizer = new OAuthParameters();
    authorizer.consumerKey = "anonymous";
    authorizer.signer = signer;
    authorizer.token = credentials.token;
    return authorizer;
  }
}




when i am using this code i am getting this error:


Invalid scope: https://apps-apis.google.com/a/feeds/user/2.0

com.google.api.client.http.HttpResponseException: 400 Bad Request
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:209)
    at com.google.api.client.auth.oauth.AbstractOAuthGetToken.execute(AbstractOAuthGetToken.java:64)
    at com.google.api.client.sample.docs.v3.Auth.authorize(Auth.java:75)
    at com.google.api.client.sample.docs.v3.DocsSample.authorize(DocsSample.java:90)
    at com.google.api.client.sample.docs.v3.DocsSample.main(DocsSample.java:49)

Gunjan Sharma

unread,
Aug 3, 2011, 1:36:15 AM8/3/11
to google-app...@googlegroups.com
Hello Neha

The scope that you are using is "https://apps-apis.google.com/a/feeds/user/2.0"
If you are attempting to make calls to the Provisioning API, the OAuth scope should be "https://apps-apis.google.com/a/feeds/user/"
The scope depends on the feeds you want to have access to. If you want to use other APIs, please check the relevant documentation pages for the correct scopes to use.
 
For more information about Provisioning API OAuth scopes, visit:

--
Thanks
Gunjan Sharma

Neha Chandra

unread,
Aug 10, 2011, 4:24:53 AM8/10/11
to google-app...@googlegroups.com

Hi,

Now when i am using the same code its gives error at the following line :

verifier = callbackServer.waitForVerifier(tempToken);

 and

 the error is:        2011-08-10 13:18:13.368::WARN:  EXCEPTION
java.lang.IllegalAccessError: tried to access method org.mortbay.util.Utf8StringBuffer.<init>(I)V from class org.mortbay.jetty.HttpURI





--
You received this message because you are subscribed to the Google Groups "Google Apps Domain Information and Management APIs" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-apps-mgmt-apis/-/YZjn9eD3htIJ.

To post to this group, send email to google-app...@googlegroups.com.
To unsubscribe from this group, send email to google-apps-mgmt...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-apps-mgmt-apis?hl=en.

Claudio Cherubino

unread,
Aug 11, 2011, 1:31:16 AM8/11/11
to google-app...@googlegroups.com
Hi Neha,

According to your last message, the exception that you are getting now doesn't seem OAuth-specific, but instead it looks like it may be due to a bug in the Java library you are using (http://code.google.com/p/google-api-java-client/).
Please try asking for support in the dedicated channels:


Thanks
Claudio
Reply all
Reply to author
Forward
0 new messages