简体   繁体   English

Google Drive REST API-仅一个用户的无效权限值

[英]Google Drive REST API - Invalid permission value for only one user

I implemented Google Drive file permissions into my application. 我在应用程序中实现了Google云端硬盘文件权限。 Everything works perfectly, only for one user (email), when I try to insert a permission , I get 一切正常,仅对一个用户(电子邮件)有效,当我尝试插入权限时

bad request (400): Invalid permission value 错误的请求(400):无效的权限值

Anyone has an idea why would I get this error just for one user? 任何人都有一个主意,为什么我只会为一个用户收到此错误? I don't see any restrictions for this user, but maybe I missed something. 我没有看到对此用户的任何限制,但也许我错过了一些东西。

Here is my insert permission function (I am using google api client (REST API v2)): 这是我的插入权限功能(我正在使用Google API客户端 (REST API v2)):

public function insert_permission($FileID, $Value, $Type, $Role, $OptParams = array(), $Service = NULL) {
    if(empty($Service)) {
       $Client = $this->get_client_sa();
       $Service = new Google_Service_Drive($Client);
    }

    $NewPermission = new Google_Service_Drive_Permission();
    $NewPermission->setValue($Value);
    //$NewPermission->setEmailAddress($Value);
    $NewPermission->setType($Type);
   // commenter additional role
   if($Role == "commenter") {
       $Role = "reader";
       $NewPermission->setAdditionalRoles(["commenter"]);
   }
    $NewPermission->setRole($Role);

    $i = 0;
    $maxTries = 3;
    $ErrorMessage = "";
    while($i < $maxTries) {
        try {
            return $Service->permissions->insert($FileID, $NewPermission, $OptParams);
        } catch (Exception $E) {
            $ErrorMessage = $E->getMessage();
            if($E->getCode() != 500)
                $i++;
        }
    }

    $this->session->set_userdata("error", $ErrorMessage);
    return $E;
}

While I was debugging I created var_dump($httpRequest); 在调试时,我创建了var_dump($httpRequest); before calling $this->client->execute($httpRequest) , and I got this object (I deleted user email, file id and authorization token from the object for security and privacy reasons): 在调用$this->client->execute($httpRequest) ,我得到了这个对象(出于安全和隐私原因,我从该对象中删除了用户电子邮件,文件ID和授权令牌):

object(Google_Http_Request)#69 (15) {
  ["batchHeaders":"Google_Http_Request":private]=>
  array(3) {
    ["Content-Type"]=>
    string(16) "application/http"
    ["Content-Transfer-Encoding"]=>
    string(6) "binary"
    ["MIME-Version"]=>
    string(3) "1.0"
  }
  ["queryParams":protected]=>
  array(0) {
  }
  ["requestMethod":protected]=>
  string(4) "POST"
  ["requestHeaders":protected]=>
  array(2) {
    ["content-type"]=>
    string(31) "application/json; charset=UTF-8"
    ["authorization"]=>
    string(183) "token_string"
  }
  ["baseComponent":protected]=>
  string(26) "https://www.googleapis.com"
  ["path":protected]=>
  string(72) "/drive/v2/files/file_id/permissions"
  ["postBody":protected]=>
  string(64) "{"role":"writer","type":"user","value":"user_email"}"
  ["userAgent":protected]=>
  NULL
  ["canGzip":protected]=>
  NULL
  ["responseHttpCode":protected]=>
  NULL
  ["responseHeaders":protected]=>
  NULL
  ["responseBody":protected]=>
  NULL
  ["expectedClass":protected]=>
  string(31) "Google_Service_Drive_Permission"
  ["expectedRaw":protected]=>
  bool(false)
  ["accessKey"]=>
  NULL
}

Everything looks OK to me and as I already said it works for all other users. 一切对我来说看起来都不错,就像我已经说过的那样,它对所有其他用户都适用。 I tested this call with Postman for the same user that is giving me problems and it worked, so there should be something wrong with my code. 我与给我带来问题的同一个用户用Postman测试了此调用,并且该调用正常了,因此我的代码应该有问题。

Now I am totally embarrassed. 现在我完全不好意思了。 I was not validating user email input correctly so it had a space character at the end and that was the only problem. 我没有正确验证用户的电子邮件输入,因此结尾处带有空格,这是唯一的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM