Google Drive API V3: Creating file permissions for a domain

时间:2017-04-10 02:49:49

标签: javascript google-drive-api file-permissions

Trying to add permissions to a file via Google Drive's API V3 and I ran into the error below. I want to allow requests from mta.io, my site, to able to read the file. The error seems to come from what domain I pass in the body of request for example, example.com works fine and permissions are granted to it. Do I need to whitelist my domain in order to give it permissions to the file?

Works:

{
  "role": "reader",
  "type": "domain",
  "domain": "example.com"
}

Doesn't work:

{
  "role": "reader",
  "type": "domain",
  "domain": "mta.io"
}

Error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "The specified domain is invalid or not applicable for the given permission type.",
    "locationType": "other",
    "location": "permission.domain"
   }
  ],
  "code": 400,
  "message": "The specified domain is invalid or not applicable for the given permission type."
 }
}

I'm using the try it feature found on the API's site.

2 个答案:

答案 0 :(得分:1)

想出来,你只能使用G Suite域名。 这是一个无赖,但为了与域名共享文件权限,您需要拥有G Suite帐户并验证您拥有该域名 - 域名需要与您的G Suite帐户相关联。

https://developers.google.com/drive/v3/web/about-permissions#types_and_values

  

例如,具有某种类型域的权限可能具有thecompany.com的域,表明该权限将授予给定角色给G Suite域中的所有用户thecompany.com

答案 1 :(得分:0)

基于此related thread,这只能在同一域中的用户之间进行,并且服务帐户不属于任何域。

  

您最好的选择可能是创建服务帐户有权访问的团队驱动器,并执行两个阶段的过程:

     
      
  1. 使用服务帐户将文件移动到团队驱动器中。 Files.update addParents参数设置为团队驱动器ID。
  2.   
  3. 使用域用户将文件移出团队驱动器。将addParents参数设置为root(或某个目标文件夹的ID)并将removeParents参数设置为团队驱动器ID的Files.update
  4.   

这是另一个可能有用的SO帖子:Google Drive SDK - change item sharing permissions