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; 
} 
相關問題