我如何在PHP中的文档的谷歌页面上创建权限



如何在文档的谷歌工作表上创建权限。这里显示错误

{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}

这是我的代码。我使用php库。

function insertPermission($fileId) {
$client = $this->getClient();
$client->setScopes(Google_Service_Drive::DRIVE);
$service = new Google_Service_Drive($client);
$newPermission = new Google_Service_Drive_Permission(
array(
"role"=> "writer",
"type"=> "domain",)  
);
try {
return $service->permissions->create($fileId, $newPermission);
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
return NULL;
}

设置权限后,它被拒绝并返回此错误。

permissions.create方法可用于将权限插入谷歌驱动器上的文件中。

POST https://www.googleapis.com/drive/v3/files/fileId/permissions
{
"role": "writer",
"type": "user",
"emailAddress": "test@test.com"
}

为了运行上述请求,当前经过身份验证的用户必须已经使用以下范围进行了身份验证,并且当然对已经的文件具有权限

  • https://www.googleapis.com/auth/drive
  • https://www.googleapis.com/auth/drive.file

权限不足

表示与您进行身份验证的用户没有授予您的应用程序进行这些更改的权限,或者他们自己没有权限。我要做的第一件事是检查应用程序请求的作用域,添加所需的作用域并重新验证用户身份,然后重试。

最新更新