gpt4 book ai didi

java - 尝试检索 Google 电子表格时出现“AuthSub token 范围错误”

转载 作者:行者123 更新时间:2023-12-02 08:24:02 25 4
gpt4 key购买 nike

我的代码是:(敏感信息已删除)

SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1");
// service.setUserCredentials(<email>, <pw>);

GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey("xxx.yyy.no");
oauthParameters.setOAuthConsumerSecret("XXX");
oauthParameters.setOAuthToken("YYYY");
oauthParameters.setOAuthTokenSecret("ZZZZ");
oauthParameters.setScope("https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/");

service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());

// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");

// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();

// Iterate through all of the spreadsheets returned
for (SpreadsheetEntry spreadsheet : spreadsheets) {
// Print the title of this spreadsheet to the screen
System.out.println(spreadsheet.getTitle().getPlainText());
}

问题:

WARNING: Authentication error: Unable to respond to any of these challenges: {authsub=WWW-Authenticate: AuthSub realm="https://www.google.com/accounts//AuthSubRequest"}

com.google.gdata.util.AuthenticationException: Token invalid - AuthSub token has wrong scope

我尝试了 clientLogin 方法(setUserCredentials(, )),效果很好。我也知道我的 OAuthConsumerKey、OAuthConsumerSecret、OAuthToken 和 OAuthTokenSecret 可以工作,因为我使用它们访问不同的提要(picasa)我尝试过设置上述 3 个范围的不同组合,但没有成功。我见过thisthis ,但还是没有运气。

任何帮助将不胜感激。

最佳答案

看看this answer .

尝试删除以下目录:

$HOME/.credentials

再次运行该程序后,它会进行回调并要求您在 Google Console 中为您的应用程序授予权限,现在它可以正常工作了。

关于java - 尝试检索 Google 电子表格时出现“AuthSub token 范围错误”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11947132/

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