1

I'm trying to get the admin state of a user on a Google Apps domain.

I therefore have put the CONSUMER_KEY and CONSUMER_SECRET I got from the Google Marketplace's listing of my App into my Code.

String CONSUMER_KEY = "748096634522.apps.googleusercontent.com";
String CONSUMER_SECRET = "PK/Wx/9sbLkz5hhj6rq6LKCZ";

And I've authorized the application to have access to the scope

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

But when I try to access the URL

 https://apps-apis.google.com/a/feeds/user/2.0/domain.com/username%40domain.com

I get the following error:

javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract com.icada.idea.client.LoginInfo com.icada.idea.client.LoginService.login(java.lang.String,java.lang.String)' threw an unexpected exception: java.lang.RuntimeException: com.google.gdata.client.authn.oauth.OAuthException: oauth_token does not exist.

Trying on Googles OAuth playground however works perfectly, whith the data provided above.

Here is my code:

private boolean isAdmin (String userEmail, String domain) {
  boolean ret= false;

  String CONSUMER_KEY = "748096634522.apps.googleusercontent.com";
  String CONSUMER_SECRET = "PK/Wx/9sbLkz5hhj6rq6LKCZ";

  GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
  oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
  oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
  oauthParameters.setScope ("https://apps-apis.google.com/a/feeds/user/");

  com.google.gdata.client.appsforyourdomain.UserService client
    = new com.google.gdata.client.appsforyourdomain.UserService ("Idea");
  try {
    client.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
    URL feedUrl = new URL("https://apps-apis.google.com/a/feeds/user/2.0/"
      + domain +"/"+ java.net.URLEncoder.encode (userEmail));

    UserFeed resultFeed = client.getFeed(feedUrl, UserFeed.class);
    for (UserEntry entry : resultFeed.getEntries()) {
      if (entry.getLogin ().getAdmin ().equals (Boolean.TRUE)) ret= true;
      else ret= false;
    }
  }
  catch (OAuthException ex) {
    log.severe (ex.getMessage () + ex.toString () + ex.getCause ()
      + ex.getStackTrace ().toString ());
    ex.printStackTrace();
  }
  [more catch-blocks...]

  return ret;
}

Any idea, why it says "oauth_token does not exist"?

3
  • Could you please post the https oauth request that gets sent over the wire Commented Dec 8, 2010 at 16:33
  • I don't know how I could do that. For the program runs on Google App Engine (where I obviously don't have access to) and the other side is the server my Google Apps account is running. So its 2 servers, I don't controll. Commented Dec 22, 2010 at 7:49
  • I am having the same trouble. Commented Jan 29, 2011 at 7:09

1 Answer 1

2

Add this line to your code.

oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);

This may solve your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

This solved no auth_token, but here what i got next: java.lang.NullPointerException: No authentication header information

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.