【发布时间】:2015-11-11 21:59:51
【问题描述】:
我想在 Android 中集成 Google Drive(用于创建文件夹和电子表格)和 Sheets API(用于填充电子表格),而不使用 Account Manager 进行身份验证。因此,我使用Drive API v2 Client Library for Java 进行驱动器集成,使用Sheets API 进行电子表格。我已经成功实现了 OAuth2.0 身份验证和驱动集成(创建文件夹和电子表格),但是由于“x 方法未为 y 定义”类型的错误,我无法使用 Sheet API。
我授权 Sheet API 服务如下:
SpreadsheetService service = new SpreadsheetService("Aplication-name");
service.setAuthSubToken(credential.getAccessToken());
我可以打印电子表格列表。但是,当我尝试使用 setColCount(int) 和 setRowCount(int) 编辑工作表尺寸时,它显示以下错误:
未定义类型 WorksheetEntry 的方法 setColCount(int)
未定义类型 WorksheetEntry 的方法 setRowCount(int)
但是根据Sheets API Documentation,这些方法应该如下工作:
// Get the first worksheet of the first spreadsheet.
// TODO: Choose a worksheet more intelligently based on your
// app's needs.
WorksheetFeed worksheetFeed = service.getFeed(
spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class);
List<WorksheetEntry> worksheets = worksheetFeed.getEntries();
WorksheetEntry worksheet = worksheets.get(0);
// Update the local representation of the worksheet.
worksheet.setTitle(new PlainTextConstruct("Updated Worksheet"));
worksheet.setColCount(5);
worksheet.setRowCount(15);
// Send the local representation of the worksheet to the API for
// modification.
worksheet.update();
我可以使用 worksheet.getColCount() 和 worksheet.getRowCount() 方法,但是 set 方法不起作用。
我已经按照here 的说明导入了以下用于 Drive 集成的 JAR:
google-api-client-1.20.0.jar
google-oauth-client-1.20.0.jar
google-http-client-1.20.0.jar
jsr305-1.3.9.jar
google-http-client-jackson2-1.20.0.jar
jackson-core-$2.1.3.jar
google-api-client-android-1.20.0.jar(适用于 SDK >= 2.1)
google-http-client-android-1.20.0.jar
并遵循给定 here 的表格集成说明的 JAR:
gdata-appsforyourdomain-1.0
gdata-base-1.0
gdata-calendar-1.0
gdata-client-1.0
gdata-codesearch-1.0
gdata-photos-1.0
gdata-spreadsheet-1.0
guava-11.0.2
jsr305
javax.mail
可能是因为导入的 JAR 之间存在某种冲突吗? 任何帮助表示赞赏。提前致谢!
【问题讨论】:
标签: android google-drive-api google-sheets