[英]Google Drive REST API - Invalid permission value for only one user
我在應用程序中實現了Google雲端硬盤文件權限。 一切正常,僅對一個用戶(電子郵件)有效,當我嘗試插入權限時 ,
錯誤的請求(400):無效的權限值
任何人都有一個主意,為什么我只會為一個用戶收到此錯誤? 我沒有看到對此用戶的任何限制,但也許我錯過了一些東西。
這是我的插入權限功能(我正在使用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;
}
在調試時,我創建了var_dump($httpRequest);
在調用$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
}
一切對我來說看起來都不錯,就像我已經說過的那樣,它對所有其他用戶都適用。 我與給我帶來問題的同一個用戶用Postman測試了此調用,並且該調用正常了,因此我的代碼應該有問題。
現在我完全不好意思了。 我沒有正確驗證用戶的電子郵件輸入,因此結尾處帶有空格,這是唯一的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.