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)
サービス変数の関数で遊んでみましたが、1 行コメントされていることがわかります。RefreshToken の代わりに AccessToken を試してみましたが、上記のエラーが表示されます。
このエラーが理解できません: どこから来たのですか? なぜそれが起こるのですか?どうすれば修正できますか?
誰かが私を助けることができれば、それは素晴らしいことです。また情報があればまた来ます。