Domanda

Sto cercando di ottenere lo stato amministratore di un utente su un dominio Google Apps.

Ho quindi messo il CONSUMER_KEY e CONSUMER_SECRET ho ottenuto dal Marketplace di Google della messa in vendita della mia App nel mio codice.

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

E ho autorizzato l'applicazione per avere accesso al campo di applicazione

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

Ma quando provo ad accedere all'URL

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

ottengo il seguente errore:

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.

Googles OAuth parco giochi tuttavia funziona perfettamente, whith i dati forniti in precedenza.

Ecco il mio codice:

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;
}

Qualche idea, perché si dice "oauth_token non esiste"?

È stato utile?

Soluzione

Aggiungi questa riga al codice.

oauthParameters.setOAuthType (OAuthType.TWO_LEGGED_OAUTH);

Questo potrebbe risolvere il problema.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top