我正在尝试使用 Google 电子表格,但遇到了一个我无法理解的问题。
以下是我解释自己之前的代码:
SpreadsheetService service =
new SpreadsheetService("MySpreadsheetIntegration-v1");
service.setOAuth2Credentials(credential);
//service.setHeader("Authorization", "Bearer "+credential.getRefreshToken());
// TODO: Authorize the service object for a specific user (see other sections)
// 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 = null;
try {
feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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());
}
我要做的是阅读变量凭证指向的帐户中可用的电子表格。我有 AccessToken 和 RefreshToken 那里。
当我运行代码时发生的情况是 Try Catch 进入 Catch 并出现以下错误:
Exception in thread "main" java.lang.NullPointerException: No authentication header information
at com.google.gdata.util.AuthenticationException.initFromAuthHeader(AuthenticationException.java:96)
at com.google.gdata.util.AuthenticationException.<init>(AuthenticationException.java:67)
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:608)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
at DriveCommandLine.main(DriveCommandLine.java:69)
我玩过服务变量中的函数,如您所见,我有一行注释。我尝试使用 AccessToken 而不是 RefreshToken ,它仍然给我上面写的错误。
我无法理解这个错误:它来自哪里?为什么会这样?我该如何解决?
如果有人可以帮助我,那就太好了。如果我有任何信息,我会回来提供更多信息。