我已经使用Google Drive Android API创建了一个文件来驱动root。如何获取此文件ID以使用Google客户端库共享?如何获取Google Drive文件ID
获得DriveFileResult在ResultCallback<DriveFileResult>
回调返回Null:
String fileId = result.getDriveFile().getDriveId().getResourceId();
我已经使用Google Drive Android API创建了一个文件来驱动root。如何获取此文件ID以使用Google客户端库共享?如何获取Google Drive文件ID
获得DriveFileResult在ResultCallback<DriveFileResult>
回调返回Null:
String fileId = result.getDriveFile().getDriveId().getResourceId();
回调是在本地创建的文件。当文件同步到服务器时,DriveId将只有一个resourceId。在此之前,getResourceId将返回null。
https://developer.android.com/reference/com/google/android/gms/drive/DriveId.html#getResourceId()
使用CompletionEvents到同步时发生了服务器通知。然后调用getResourceId()应该提供你所期望的。
此代码可能有助于识别存在于谷歌驱动器中的文件的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());
}
}
}
不幸的是,您正在将[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 2015-08-28 13:29:50
谢谢,但你能建议如何做这个同步? – 2014-08-29 11:02:11
听着,我的文件是在Drive中创建的,我看到了它。这是否意味着文件已经同步? – 2014-08-29 11:37:04
你不需要做任何事情来同步,它会自动发生。您可以侦听更改事件以了解资源更改的时间,包括添加resourceId:https://developers.google.com/drive/android/events – 2014-08-29 15:14:32