如何以编程方式从 android 更改对 google 驱动器照片的访问权限?

How to change access to the google drive photo programmatically from android?

我有一个应用程序。在它的帮助下,我可以在 google 驱动器上上传图像。问题是只有 google 登录用户才能看到它。我如何以编程方式制作具有 public 访问权限的上传图像?

您可以使用云端硬盘 API Permission.create 为您在 Google 云端硬盘中上传的文件创建权限。

当您使用驱动器 api 上传文件时,从响应正文中的 文件资源 获取 file id。然后使用 Permission.create 公开共享文件。

示例请求正文:

文件 ID:1P8vNKbOXGlzity4ZvAjEpfMDEH_xxxxxx

{
  "role": "reader",
  "type": "anyone"
}

示例响应正文:

{
 "kind": "drive#permission",
 "id": "anyoneWithLink",
 "type": "anyone",
 "role": "reader",
 "allowFileDiscovery": false
}

输出:

  • 通过使用这种 link 格式 https://drive.google.com/file/d/<file id>/view,即使您没有使用 Google 帐户登录,您也可以查看上传的图片。