gpt4 book ai didi

java - token 无效 - token 无效 : Invalid user for the two legged OAuth

转载 作者:行者123 更新时间:2023-12-02 07:54:03 27 4
gpt4 key购买 nike

我正在尝试使用 OAuth2.0 访问 google 文档。我已经从 Google API 控制台获取了客户端 ID 和 key 。但是当我运行这段代码时,我收到了异常。如果我遗漏了什么,有人可以建议我吗?

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

异常(exception):

com.google.gdata.util.AuthenticationException: Token invalid - Invalid token: Invalid user for the two legged OAuth

token 无效 - 无效 token :两条腿 OAuth 的用户无效

token 无效 - token 无效:两条腿 OAuth 的用户无效

错误401

最佳答案

xoauth_requestor_id 参数仅适用于 2-legged Oauth (2LO),用于对 Google Apps 用户进行身份验证。我认为不可能使用 2LO 对常规 Gmail 用户进行身份验证。

您看过这里的 3 足 Oauth 示例吗 http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples

关于java - token 无效 - token 无效 : Invalid user for the two legged OAuth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9869994/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com