2013-09-30 31 views
0

我需要使用方法getIdForEmail來管理驅動文件的權限,然而在使用此方法的php客戶端庫的文檔中有一個示例,但是瀏覽它似乎尚未實現的源代碼。是否有一種解決方法,直到它被添加到發行版或可以添加(到Google_DriveService.php)的修補程序?google-api-php-client不包含權限方法「getIdForEmail」

使用php client library版本0.6.6的最新版本。

編輯: 解決此問題的一個不太方便的解決方法是在用戶第一次連接時獲取權限ID並將其保存到應用程序的數據庫供以後使用。儘管許多應用程序能夠交換電子郵件地址以獲得許可ID,但無論用戶是否經過身份驗證,它都會更清晰。

EDIT2:檢查版本0.6.7仍然沒有getIdForEmail函數。

回答

0

功能確實存在這裏

https://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/Google_DriveService.php?r=577

在DriveService.php文件

所以在Google_PermissionsServiceResource類添加

/** 
* Returns the permission ID for an email address. (permissions.getIdForEmail) 
* 
* @param string $email The email address for which to return a permission ID 
* @param array $optParams Optional parameters. 
* @return Google_PermissionId 
*/ 
public function getIdForEmail($email, $optParams = array()) { 
    $params = array('email' => $email); 
    $params = array_merge($params, $optParams); 
    $data = $this->__call('getIdForEmail', array($params)); 
    if ($this->useObjects()) { 
    return new Google_PermissionId($data); 
    } else { 
    return $data; 
    } 
} 

然後替換以$這個開頭的行 - >權限

$this->permissions = new Google_PermissionsServiceResource($this, $this->serviceName, 'permissions', json_decode('{"methods": {"delete": {"id": "drive.permissions.delete", "path": "files/{fileId}/permissions/{permissionId}", "httpMethod": "DELETE", "parameters": {"fileId": {"type": "string", "required": true, "location": "path"}, "permissionId": {"type": "string", "required": true, "location": "path"}}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]}, "get": {"id": "drive.permissions.get", "path": "files/{fileId}/permissions/{permissionId}", "httpMethod": "GET", "parameters": {"fileId": {"type": "string", "required": true, "location": "path"}, "permissionId": {"type": "string", "required": true, "location": "path"}}, "response": {"$ref": "Permission"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive.metadata.readonly", "https://www.googleapis.com/auth/drive.readonly"]}, "getIdForEmail": {"id": "drive.permissions.getIdForEmail", "path": "permissionIds/{email}", "httpMethod": "GET", "parameters": {"email": {"type": "string", "required": true, "location": "path"}}, "response": {"$ref": "PermissionId"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.appdata", "https://www.googleapis.com/auth/drive.apps.readonly", "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive.metadata.readonly", "https://www.googleapis.com/auth/drive.readonly"]}, "insert": {"id": "drive.permissions.insert", "path": "files/{fileId}/permissions", "httpMethod": "POST", "parameters": {"emailMessage": {"type": "string", "location": "query"}, "fileId": {"type": "string", "required": true, "location": "path"}, "sendNotificationEmails": {"type": "boolean", "default": "true", "location": "query"}}, "request": {"$ref": "Permission"}, "response": {"$ref": "Permission"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]}, "list": {"id": "drive.permissions.list", "path": "files/{fileId}/permissions", "httpMethod": "GET", "parameters": {"fileId": {"type": "string", "required": true, "location": "path"}}, "response": {"$ref": "PermissionList"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive.metadata.readonly", "https://www.googleapis.com/auth/drive.readonly"]}, "patch": {"id": "drive.permissions.patch", "path": "files/{fileId}/permissions/{permissionId}", "httpMethod": "PATCH", "parameters": {"fileId": {"type": "string", "required": true, "location": "path"}, "permissionId": {"type": "string", "required": true, "location": "path"}, "transferOwnership": {"type": "boolean", "default": "false", "location": "query"}}, "request": {"$ref": "Permission"}, "response": {"$ref": "Permission"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]}, "update": {"id": "drive.permissions.update", "path": "files/{fileId}/permissions/{permissionId}", "httpMethod": "PUT", "parameters": {"fileId": {"type": "string", "required": true, "location": "path"}, "permissionId": {"type": "string", "required": true, "location": "path"}, "transferOwnership": {"type": "boolean", "default": "false", "location": "query"}}, "request": {"$ref": "Permission"}, "response": {"$ref": "Permission"}, "scopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]}}}', true)); 

更新:它看起來像這樣的API客戶端的新版本支持(1.0)https://github.com/google/google-api-php-client