1

Android에서 Google 스프레드 시트 API v4를 사용하고 있습니다.Google 스프레드 시트 가져 오기 시트 API v4 (자바)를 사용하여 마지막으로 수정 한 날짜

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

이 기능은 스프레드 시트 API에서 사용할 수 없지만 응답에 'modifiedTime'이 포함 된 드라이브 API의 files.get 메소드를 사용할 수 있습니다. 기본적으로 수정 된 시간은 포함되지 않으므로 'fields'매개 변수에서 명시 적으로 요청해야합니다.

+0

,하지만 나는 확실히 당신에게 신용을주고 있습니다. 때로는 "당신이 어차피!"라는 것을 아는 것이 중요합니다. 또한 어디로 갈까요 (Drive API files.get). 아주 많이 고마워! – LimaNightHawk

1

Sheets API v4에서는 수행 할 수없는 것처럼 보입니다.

그러나 호환 가능한 Google 드라이브 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; 
}