Google drive api 如何获取Google驱动器文件ID

Google drive api 如何获取Google驱动器文件ID,google-drive-api,google-drive-android-api,Google Drive Api,Google Drive Android Api,我已经创建了一个文件来驱动根使用谷歌驱动器Android API。我怎样才能获得这个文件ID来使用Google客户端库共享它 在ResultCallback回调中获取DriveFileResult返回空值: String fileId = result.getDriveFile().getDriveId().getResourceId(); 回调指向本地创建的文件。当文件同步到服务器时,DriveId将仅具有resourceId。在此之前,getResourceId将返回null 用于在与服

我已经创建了一个文件来驱动根使用谷歌驱动器Android API。我怎样才能获得这个文件ID来使用Google客户端库共享它

ResultCallback
回调中获取DriveFileResult返回空值:

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

回调指向本地创建的文件。当文件同步到服务器时,DriveId将仅具有resourceId。在此之前,getResourceId将返回null


用于在与服务器同步时收到通知。然后调用getResourceId()应该可以实现您的期望。

此代码可能有助于识别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());
        }
    }
}
publicstaticvoidmain(字符串[]args)引发IOException{
//构建新的授权API客户端服务。
驱动器服务=getDriveService();
//打印最多10个文件的名称和ID。
FileList结果=service.files().list()
.setMaxResults(10)
.execute();
List files=result.getItems();
如果(files==null | | files.size()==0){
System.out.println(“未找到文件”);
}否则{
System.out.println(“文件:”);
用于(文件:文件){
System.out.printf(“%s(%s)\n”、file.getTitle()、file.getId());
}
}
}

谢谢,但您能建议如何进行同步吗?听着,我的文件是在驱动器中创建的,我看到了。这是否意味着文件已经同步?您不必做任何事情来同步,它将自动发生。您可以监听更改事件,以了解资源何时更改,包括添加resourceId:@CherylSimon谢谢!使用change event listener,我得到了一个Id为file
ChangeEvent.getDriveId().getResourceId()
的文件,它似乎可以工作。现在尝试插入该文件的新权限。可以找到此问题的最新和正确解决方案。很遗憾,您将Api与。这不是一个好主意,已经得到了充分的回答