2010-11-30 36 views
1

J'essaie d'obtenir l'état d'administration d'un utilisateur sur un domaine Google Apps.RuntimeException: com.google.gdata.client.authn.oauth.OAuthException: oauth_token n'existe pas

J'ai donc mis le CONSUMER_KEY et CONSUMER_SECRET que j'ai obtenu de la liste de mon application Google Marketplace dans mon code.

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

Et j'ai autorisé la demande d'avoir accès à la portée

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

Mais quand je tente d'accéder à l'URL

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

J'obtiens l'erreur suivante:

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. 

Essayer sur Googles OAuth playground cependant fonctionne parfaitement, avec les données fournies ci-dessus.

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

Toute idée, pourquoi il dit "oauth_token n'existe pas"?

+0

Pourriez-vous s'il vous plaît poster la demande https oauth qui est envoyé sur le fil –

+0

Je ne sais pas comment je pourrais le faire. Pour le programme fonctionne sur Google App Engine (où je n'ai évidemment pas accès) et l'autre côté est le serveur mon compte Google Apps est en cours d'exécution. Donc, ses 2 serveurs, je ne contrôle pas. – JochenJung

+0

J'ai le même problème. –

Répondre

2

Ajouter cette ligne à votre code.

oauthParameters.setOAuthType (OAuthType.TWO_LEGGED_OAUTH);

Cela peut résoudre votre problème.

+0

Cela a résolu non auth_token, mais voici ce que j'ai eu à côté: java.lang.NullPointerException: Aucune information d'en-tête d'authentification – tevch