我試圖使用OAuth 2.0訪問Google的文檔列表API 3.0,但我遇到了401錯誤的一些麻煩。OAuth - 無效令牌:不允許使用請求令牌
用戶後接受了,我的代碼如下:
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CLIENT_ID);
oauthParameters.setOAuthConsumerSecret(CLIENT_SECRET);
oauthParameters.setOAuthToken(token);
oauthParameters.setOAuthTokenSecret(tokenSecret);
oauthParameters.setScope("https://docs.google.com/feeds/");
service = new DocsService("myapp");
service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
DocumentListFeed feed = service.getFeed(new URL("https://docs.google.com/feeds/default/private/full/?v=3"), DocumentListFeed.class);
然後,在最後一行-getFeed() - 拋出異常:
com.google.gdata.util.AuthenticationException: Token invalid - Invalid token: Request token used when not allowed.
<HTML>
<HEAD>
<TITLE>Token invalid - Invalid token: Request token used when not allowed.</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - Invalid token: Request token used when not allowed.</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
這是怎麼回事?在一個靜態的主要測試類中就像一個魅力,但是當我在服務器上運行它時,這條線不再起作用。任何想法?
解決
訪問令牌需要檢索這種方式,具有GoogleOAuthHelper,不直接與GoogleOAuthParameters:
String accessToken = oauthHelper.getAccessToken(oauthParameters);
難道你把你的解決方案在回答中並接受的答案嗎? 這種方式問題被標記爲已解決,如果任何人在這篇文章(出於任何原因)獲得答案將很容易找到。 – 2012-04-20 12:18:53
這是什麼oauthHelper? – 2012-08-14 09:12:17