0
我試圖從com.google.gdata.data.spreadsheet.SpreadsheetEntry中獲取工作表。
認證工作:
GoogleCredential credential = authorize();
SpreadsheetService service = new SpreadsheetService("My Project");
service.setProtocolVersion(SpreadsheetService.Versions.V3);
service.setOAuth2Credentials(credential);
我可以得到電子表格條目:
URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
但只要我所說的spreadsheet.getWorksheets()方法,我得到以下錯誤:
com.google.gdata.client.GoogleService $ SessionExpiredException:未授權
我的授權方法如下所示:
File p12 = new File("src/main/resources/My Project-e81707237c5b.p12");
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
String [] SCOPESArray= {
"https://spreadsheets.google.com/feeds/spreadsheets/private/full"
};
final List SCOPES = Arrays.asList(SCOPESArray);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("[email protected]account.com")
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(p12)
.build();