How to get Google Drive file ID

后端 未结 2 1588
感动是毒
感动是毒 2020-12-06 22:20

I\'ve created a file to Drive root using Google Drive Android API. How can I get this file ID to share it using Google Client Library?

Getting DriveFileResult in

相关标签:
2条回答
  • 2020-12-06 23:00

    The callback is to the file being created locally. The DriveId will only have a resourceId when the file is synced to the server. Until then getResourceId will return null.

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

    Use CompletionEvents to be notified when syncing with the server has occurred. Then calling getResourceId() should deliver what you are expecting.

    0 讨论(0)
  • 2020-12-06 23:18

    this code might help to identify the id for a file present in the google drive.

        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 讨论(0)
提交回复
热议问题