2014-08-28 1 views
2

Google 드라이브 Android API를 사용하여 루트로 파일을 만들었습니다. Google 클라이언트 라이브러리를 사용하여이 파일 ID를 공유하려면 어떻게해야합니까?Google 드라이브 파일 ID 받기 방법

ResultCallback<DriveFileResult> 콜백 DriveFileResult을 얻는 것은 NULL을 반환 : 파일이 로컬로 생성되는에

String fileId = result.getDriveFile().getDriveId().getResourceId(); 

답변

3

콜백입니다. DriveId는 파일이 서버에 동기화 될 때 resourceId 만 갖습니다. 그때까지 getResourceId는 null을 리턴합니다. 서버가 발생와 동기화 할 때

https://developer.android.com/reference/com/google/android/gms/drive/DriveId.html#getResourceId()

사용 CompletionEvents

통지합니다. 그런 다음 getResourceId()를 호출하면 예상 한 것을 제공해야합니다.

+0

감사합니다.하지만이 동기화 방법을 제안 할 수 있습니까? –

+0

들어요, 내 파일이 드라이브에 만들어 졌는데 봤어요. 이미 동기화 된 파일을 의미합니까? –

+2

동기화 할 작업이 없어도 자동으로 수행됩니다. resourceId를 추가하는 등 변경 이벤트를 수신하여 리소스가 언제 변경되는지 확인할 수 있습니다. https://developers.google.com/drive/android/events –

0

이 코드는 Google 드라이브에있는 파일의 ID를 식별하는 데 도움이 될 수 있습니다.

public static void main(String[] args) throws IOException { 
    // Build a new authorized API client service. 
    Drive service = getDriveService(); 

    // Print the names and IDs for up to 10 files. 
    FileList result = service.files().list() 
     .setMaxResults(10) 
     .execute(); 
    List<File> files = result.getItems(); 
    if (files == null || files.size() == 0) { 
     System.out.println("No files found."); 
    } else { 
     System.out.println("Files:"); 
     for (File file : files) { 
      System.out.printf("%s (%s)\n", file.getTitle(), file.getId()); 
     } 
    } 
} 
+0

아쉽게도 [REST] (https://developers.google.com/drive/web/about-sdk) API와 [GDAA] (https://developers.google.com/drive/android/)를 혼합합니다. 소개). 좋은 생각이 아니에요, 그것은 [여기 이미] 답변되었습니다 (http://stackoverflow.com/questions/22874657/unpredictable-result-of-driveid-getresourceid-in-google-drive-android-api/31553269#31553269) – seanpj