2017-05-23 25 views
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測試了這個調用,這個用戶給了我一些問題並且工作正常,所以我的代碼應該會出現問題。

+0

在我們可以幫助您調試代碼之前,您需要編輯您的問題並共享您的代碼。 「無效的權限值」意味着您正在嘗試爲該用戶不允許的權限設置值。 – DaImTo

+0

我編輯了我的帖子,請再次檢查。謝謝。 – Silko

回答

1

現在我很尷尬。我沒有正確驗證用戶電子郵件輸入,因此它在最後具有空格字符,這是唯一的問題。