【发布时间】:2015-08-20 15:04:58
【问题描述】:
我一直在关注有关 Google Sheets API 的文档,但无法使其正常工作。当我尝试访问电子表格时,出现以下错误:
Exception in thread "main" com.google.gdata.client.GoogleService$SessionExpiredException: Token invalid - AuthSub token has wrong scope
<HTML>
<HEAD>
<TITLE>Token invalid - AuthSub token has wrong scope</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - AuthSub token has wrong scope</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
带代码:
SpreadsheetService sheetService = new SpreadsheetService("App-v1");
sheetService.setProtocolVersion(SpreadsheetService.Versions.V3);
sheetService.setOAuth2Credentials(DriveService.getCredential());
URL mFeedURL = new URL(SPREADSHEET_FEED);
SpreadsheetFeed feed = sheetService.getFeed(mFeedURL, SpreadsheetFeed.class);
但是当我从 Google Drive 中检索文件名时,一切顺利。
我正在使用的范围和提要网址:
SPREADSHEET_FEED = "https://spreadsheets.google.com/feeds/spreadsheets/private/full"
SCOPES = Arrays.asList(DriveScopes.DRIVE_METADATA_READONLY,
"https://spreadsheets.google.com/feeds/"
);
这是具有权限或令牌的东西还是只是错误的实现?
【问题讨论】:
-
根据page,这是一条通用错误消息,适用于访问范围与您所要求的不匹配的任何情况,无论是 OAuth 还是 AuthSub。所以原因可能是因为使用了已弃用的范围。 “docs.google.com/feeds”用于文档列表 API,已于 2015 年 4 月 20 日弃用。检查此page 以替换 Drive 范围。检查是否可以通过更改范围来消除此错误。
-
@KRR 不,它不会影响它并返回相同的错误。
标签: java google-drive-api google-sheets