1
我試圖獲取用戶在Google Apps域上的管理狀態。RuntimeException:com.google.gdata.client.authn.oauth.OAuthException:oauth_token不存在
因此,我已將從Google Marketplace的應用程序列表中獲得的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.
試穿Googles OAuth playground然而,完美的作品,與上面提供的數據。
這裏是我的代碼:
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不存在」?
你可以請發佈通過電線發送的https oauth請求 – 2010-12-08 16:33:21
我不知道我該怎麼做。對於在Google App Engine上運行的程序(我顯然無法訪問)以及另一端是我的Google Apps帳戶正在運行的服務器。所以它的2臺服務器,我不控制。 – JochenJung 2010-12-22 07:49:55