0

我需要使用getIdForEmail方法来管理驱动文件的权限,文档中有一个使用这种方法的 php 客户端库的示例,但是浏览源它似乎还没有实现。在将其添加到发行版之前是否有解决方法,或者可以添加补丁(到 Google_DriveService.php)?

使用最新发布的php 客户端库版本 0.6.6。

编辑:解决此问题的一个不太方便的解决方法是在用户第一次连接时获取权限 ID,并将其保存到应用程序的数据库中以供以后使用。尽管对于许多应用程序而言,无论用户是否经过身份验证,都能够将电子邮件地址换成权限 ID 会更干净。

EDIT2:检查版本 0.6.7 仍然没有 getIdForEmail 功能。

4

1 回答 1

0

该功能确实存在here

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

所以在你的 DriveService.php 文件中添加

/**
 * 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;
  }
}

在 Google_PermissionsServiceResource 类中

然后替换以 $this->permissions 开头的行

$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

于 2013-11-23T18:29:50.253 回答