RuntimeException:com.google.gdata.client.authn.oauth.OAuthException:oauth_token不存在
我正在尝试获取 Google Apps 域中用户的管理状态。
因此,我将从 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/
但是当我尝试访问该网址时
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.
尝试 然而,根据上面提供的数据,Google 的 OAuth 游乐场 运行良好。
这是我的代码:
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 不存在”吗?
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"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此行添加到您的代码中。
oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
这可能会解决您的问题。
Add this line to your code.
oauthParameters.setOAuthType(OAuthType.TWO_LEGGED_OAUTH);
This may solve your problem.