【发布时间】:2012-04-09 19:56:17
【问题描述】:
我正在尝试使用 OAuth2.0 访问谷歌文档。我从 Google API 控制台获得了客户端 ID 和密钥。但是当我运行这段代码时,我得到了异常。如果我遗漏了任何东西,你可以给我建议吗..
String CONSUMER_KEY = ".....apps.googleusercontent.com";
String CONSUMER_SECRET = "sM52Mts_d7snVIomnJaQkjkA";
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
DocsService client = new DocsService("testing");
client.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
// Retrieve user's list of Google Docs
String user = "xesunny@gmail.com";
URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full" +
"?xoauth_requestor_id=" + user);
DocumentListFeed resultFeed = client.getFeed(feedUrl, DocumentListFeed.class);
for (DocumentListEntry entry : resultFeed.getEntries()) {
System.out.println(entry.getTitle().getPlainText());
}
例外:
com.google.gdata.util.AuthenticationException: Token invalid - Invalid token: Invalid user for the two legged OAuth
令牌无效 - 令牌无效:两条腿 OAuth 的用户无效
令牌无效 - 令牌无效:两条腿 OAuth 的用户无效
错误 401
【问题讨论】: