首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google-api-php-client不包含权限方法"getIdForEmail“

google-api-php-client不包含权限方法"getIdForEmail“
EN

Stack Overflow用户
提问于 2013-09-30 19:14:41
回答 1查看 269关注 0票数 0

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

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

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

EDIT2:已检查0.6.7版仍然没有getIdForEmail函数。

EN

回答 1

Stack Overflow用户

发布于 2013-11-24 02:29:50

该函数确实存在于此处

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

因此在DriveService.php文件中添加

代码语言:javascript
复制
/**
 * 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开头的行

使用

代码语言:javascript
复制
$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 client (1.0) https://github.com/google/google-api-php-client支持这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19092811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档