尝试检索谷歌电子表格时,“AuthSub令牌的范围错误”

时间:2012-08-14 06:49:12

标签: java oauth-2.0 gdata google-sheets

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

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工作,因为我使用它们访问不同的Feed(picasa) 我尝试过设置上述3个范围的不同组合,但没有运气。 我见过thisthis,但又一次,没有运气。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

看看this answer

尝试删除以下目录:

$HOME/.credentials

再次运行程序之后,它会进行回调并要求您在Google控制台中为您的应用程序授予权限,现在它将正常运行。

相关问题