我的代码是:(敏感信息已删除)
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 个范围的不同组合,但没有运气。我见过这个和这个,但同样,没有运气。
任何帮助将不胜感激。