如何获取 Google Drive 文件 ID [英] How to get Google Drive file ID

查看:120
本文介绍了如何获取 Google Drive 文件 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Google Drive Android API 创建了一个文件到 Drive root.如何获取此文件 ID 以使用 Google 客户端库共享它?

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?

ResultCallback回调中获取DriveFileResult返回Null:

Getting DriveFileResult in ResultCallback<DriveFileResult> callback returns Null:

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

推荐答案

回调的是本地正在创建的文件.DriveId 只有在文件同步到服务器时才会有 resourceId.在此之前,getResourceId 将返回 null.

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()

使用 CompletionEvents 在与服务器同步时收到通知.然后调用 getResourceId() 应该会提供您所期望的.

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

这篇关于如何获取 Google Drive 文件 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆