1

我使用谷歌API表在V4的Android谷歌获取最新表编辑日期。使用表API V4(JAVA)

https://developers.google.com/sheets/api/quickstart/android

我需要知道何时最后修改到片材制成(包括由用户);我需要这个家伙:

enter image description here

我想要做这样的事情:

Spreadsheet spreadsheet = sheetsService.spreadsheets().get(spreadsheetId).setIncludeGridData(true).execute(); 
    Date date = spreadsheet.getProperties().getLastEditDate(); 

但是,当然,没有这样的getLastEditDate()属性方法存在。有没有一个参数或其他API方法来获取这些数据?

更好的办法是获取每个单元格的修改日期...但我会为整个电子表格或工作表的日期作出决定。

回答

1

这在Sheets API中不可用,但您可能能够使用Drive API的files.get方法,其中包括响应中的“modifiedTime”。 (请注意,默认情况下它不包括修改的时候,你必须在“字段”参数明确地提出要求。)

+0

我想我会加入我自己的答案给别人(后下) ,但我肯定会给你信贷。有时候知道“你不能!”是很重要的。另外,去哪里(Drive API files.get)。非常感谢你! – LimaNightHawk

1

它看起来像这样不能与表API v4的工作要做。

但是......它看起来像它可以与兼容谷歌云端硬盘API V3来完成。

注:这个解决方案最好的部分是,我可以使用的身份验证和证书收集的同样的方法为两种API。例如,一旦我有获得证书的代码,我可以用其来进行API的交替和连续。

这里就是我所做的:

将此添加到我的build.gradle(我下面的表API声明所示)

compile('com.google.apis:google-api-services-sheets:v4-rev468-1.22.0') { 
    exclude group: 'org.apache.httpcomponents' 
} 
compile('com.google.apis:google-api-services-drive:v3-rev69-1.22.0') { 
    exclude group: 'org.apache.httpcomponents' 
} 

我已经使用获取帐户和凭据EasyPermissions方法。 Great example here

则...

import com.google.api.services.drive.Drive; 

...

protected Drive driveService = new Drive.Builder(transport, jsonFactory, credential) 
      .setApplicationName("My Application Name") 
      .build(); 

...异步:

private DateTime getSheetInformation() throws IOException { 

    String spreadsheetId = settings.getSpreadsheetId(); 
    Drive.Files.Get fileRequest = driveService.files().get(spreadsheetId).setFields("id, modifiedTime"); 
    File file = fileRequest.execute(); 
    if (file != null) { 
     return file.getModifiedTime(); 
    } 
    return null; 
}