1
我在应用程序中实施了Google Drive文件权限。一切完美,只为一个用户(电子邮件),当我尝试insert a permission,我得到Google Drive REST API - 只有一位用户的权限值无效
错误的请求(400):无效的许可值
任何人有一个想法,为什么我会得到这个只为一个用户出错?我没有看到这个用户的任何限制,但也许我错过了一些东西。
这里是我的insert权限的功能(我使用google api client(REST API第2版)):
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;
}
当我调试我打电话$this->client->execute($httpRequest)
之前创建var_dump($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
}
一切正常,我和我已经说过它适用于所有其他用户。我用Postman测试了这个调用,这个用户给了我一些问题并且工作正常,所以我的代码应该会出现问题。
在我们可以帮助您调试代码之前,您需要编辑您的问题并共享您的代码。 “无效的权限值”意味着您正在尝试为该用户不允许的权限设置值。 – DaImTo
我编辑了我的帖子,请再次检查。谢谢。 – Silko