【问题标题】:Google Drive API Check if File is Shared With MeGoogle Drive API 检查文件是否与我共享
【发布时间】:2017-06-02 18:28:35
【问题描述】:

我正在创建一个 Android 应用程序,它使用 Google Sheets API V4 和 Google Drive API V2 来编辑 Google 电子表格。但我有一个问题。我需要能够检查电子表格是否与登录到设备的用户共享,他们是否可以编辑它或者他们是否是所有者。我试过了
Boolean canEdit = driveService.files().get(fileId).execute().getEditable();
和
Boolean canEdit = driveService.files() .get(fileId).execute().getCapabilities().getCanEdit();
但是这两个似乎只有在用户拥有文件时才有效。我认为那是因为命令files().get(id) 只能获取用户驱动器中的文件;不是与用户共享的任何文件。我也试过
String role = driveService.permissions().get(fileId, driveService .about().get().execute().getPermissionId()).execute().getRole();
但这似乎也只在用户驱动器中查找文件。如果用户不是所有者,所有这些命令都会抛出 404 Not Found。
请帮帮我!

【问题讨论】:

    标签: java google-drive-api google-sheets-api


    【解决方案1】:

    正如Handling API Errors 中所述,404: File not found 可能是用户没有文件的读取权限。

    而且,AFAIK,需要访问用户数据的请求需要特定的访问范围。但是,如 Authorizing Android Apps 中所述,Google Drive Android API 目前仅支持 drive.file 和 drive.appfolder 授权范围。

    这样,您可能希望使用Google APIs Java Client 授权您的请求,而不是使用与您共享的search for files 的Google Drive 网络服务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多