2010-11-30 15 views
1

Google Appsドメイン上のユーザーの管理状態を取得しようとしています。RuntimeException:com.google.gdata.client.authn.oauth.OAuthException:oauth_tokenが存在しません

私は、Googleマーケットプレイスの私のアプリケーションのリストから取得したCONSUMER_KEYとCONSUMER_SECRETを私のコードに入れました。

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

そして、私は

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

範囲へのアクセス権を持っているアプリケーションを許可しました。しかし、私はURL

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

にアクセスしようとすると、私は次のエラーを取得する:

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. 

で試してみるしかし、は上記のデータで完璧に動作します。

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

任意のアイデア、それは "oauth_tokenが存在しない" と言う理由:ここで

は私のコードですか?

+0

ワイヤで送信されるhttpsのoauthリクエストを投稿してください。 –

+0

どうすればいいのか分かりません。プログラムはGoogle App Engine(私は明らかにアクセス権がない)上で実行され、もう一方はGoogle Appsアカウントが実行されているサーバーです。だから2台のサーバーは、私は制御しません。 – JochenJung

+0

私は同じ問題を抱えています。 –

答えて

2

この行をコードに追加してください。

oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);

これにより、問題が解決する場合があります。

+0

これはauth_tokenを解決しませんでしたが、次に私が得たもの:java.lang.NullPointerException:認証ヘッダー情報がありません – tevch

関連する問題