最后我使用的库是:
gdata-client-1.0.jar
gdata-client-meta-1.0.jar
gdata-core-1.0.jar
gdata-spreadsheet-3.0.jar
gdata-spreadsheet-meta-3.0.jar
google-api-client-1.12.0-beta.jar
google-api-client-android-1.12.0-beta.jar
google-http-client-1.12.0-beta.jar
google-http-client-android-1.12.0-beta.jar
google-oauth-client-1.12.0-beta.jar
gson-2.1.jar
guava-13.0.1.jar
jackson-core-asl-1.9.9.jar
jsr305-1.3.9.jar
protobuf-java-2.4.1.jar
正如 Eugenio 所建议的(谢谢!!!)我将电子表格 api 中的库与 java-client-api “混合”,在身份验证之后,我使用以下内容获取单元格
SpreadsheetEntry spreadsheet = null;
URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetFeed spreadsheetFeed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = spreadsheetFeed.getEntries();
for (SpreadsheetEntry entry : spreadsheets) {
if (entry.getTitle().getPlainText().equals(spreadsheetTitle)) {
spreadsheet = entry;
}
}
if (spreadsheet == null) {
throw new FileNotFoundException("Cannot find the required spreadsheet '" + spreadsheetTitle + "'");
}
WorksheetEntry worksheet = null;
WorksheetFeed worksheetFeed = service.getFeed(spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
for (WorksheetEntry entry : worksheets) {
if (entry.getTitle().getPlainText().equals(worksheetTitle)) {
worksheet = entry;
}
}
if (worksheet == null) {
throw new FileNotFoundException("Cannot find the required worksheet '" + worksheetTitle + "'");
}
URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);
目前我使用了“最差”的身份验证系统,我应该在 OAuth2 中打开它,但目前 ClientLogin 是以这种方式完成的:
SpreadsheetService service = new SpreadsheetService("v1");
service.setProtocolVersion(SpreadsheetService.Versions.V3);
service.setUserCredentials(email, password);