[英]Google Drive API (team drive) file permissions in php to anyone or specific domain
On the Google API explorer I tried giving the correct fileId in drive.permissions.create. 在Google API资源管理器上,我尝试在drive.permissions.create中提供正确的fileId。 I set supportsTeamDrives to true and Request body with role: reader and type: anybody.
我将supportTeamDrives设置为true,并使用角色:读者和类型:任何人来设置请求正文。 This just gives me the error:
这只是给我的错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidLinkVisibility",
"message": "Bad Request. User message: \"\""
}
],
"code": 400,
"message": "Bad Request. User message: \"\""
}
}
Same goes in my PHP code. 我的PHP代码中也是如此。 Here is as close as I can get, that looks right to me:
这是我所能找到的最接近的位置:
...
$userPermission = new Google_Service_Drive_Permission( array(
'type' => 'anyone',
'role' => 'reader',
));
$service->permissions->create( $imageId, $userPermission, array(
'supportsTeamDrives' => true,
));
...
I can't find anything on the error: 我找不到关于该错误的任何内容:
invalidLinkVisibility invalidLinkVisibility
What I need to do is to temporarily set the permission on 20-50 files in a folder to "public" (ie anyone with the link can see it) because I'm sending the webContentLink (or webViewLink, I haven't figured out which one I need to use yet) to another API to upload the images there. 我需要做的是将文件夹中20-50个文件的权限临时设置为“公开”(即,知道链接的任何人都可以看到),因为我正在发送webContentLink(或webViewLink,我还没有弄清楚)我需要使用哪一个)到另一个API上载图片。 Once this is done I'd like to remove the public access.
完成此操作后,我想删除公共访问权限。 One option would be to set the permission (with recursive public access) on the folder to public access.
一种选择是将文件夹的权限(具有递归公共访问权限)设置为公共访问权限。 I just can't figure out how I change (or rather add) permissions to a file in the Google Drive API, in PHP.
我只是不知道如何在PHP中更改(或添加)Google Drive API中的文件权限。
An alternative to this would be if there is some way to get the image thru a URL with the token included, eg 一种替代方法是,如果有某种方法可以通过包含令牌的URL获取图像,例如
$source = $files.$image1;
$context = stream_context_create( array(
'https' => array(
'header' => 'Authorization: Bearer '. $token
)
) );
$image = file_get_contents( $source, false, $context );
Where $token is the the auth token from authenticating the service, $files is https://drive.google.com/a/file/d/ and $image1 is the id of the file. 其中$ token是验证服务的身份验证令牌,$ files是https://drive.google.com/a/file/d/,而$ image1是文件的ID。 Of course when trying this I have to first logon to my Google account, which won't work since I'll have another API calling these links and posting the content to another service.
当然,在尝试此操作时,我必须先登录我的Google帐户,因为我将使用另一个API调用这些链接并将内容发布到其他服务,所以该帐户将无法使用。 Is there some way to make this work?
有什么办法可以使这项工作吗? This way I wouldn't have to worry about the file permissions (back-n-forth).
这样,我就不必担心文件权限(倒数第二个)。
you need to delete the old permissions object first , this object will have this default initial id usually : 10933160239610460256k (i found this id when i was trying to figure out this solution through analysing GDrive frontend-backend interactions) 您需要先删除旧的权限对象,该对象通常具有默认的初始ID:10933160239610460256k(当我尝试通过分析GDrive前端与后端的交互来找出此解决方案时,我找到了此ID)
$service->permissions->delete($file->id, '10933160239610460256k',array('supportsTeamDrives'=>true));
then create a new permission like this 然后像这样创建一个新的权限
$Permission = new \Google_Service_Drive_Permission(array(
'type' => 'anyone',
'role' => "reader",
'additionalRoles' => [],
'withLink' => true,
'value' =>'YOUR_TEAM_DRIVE_DOMAIN'
));
$service->permissions->create(
$file->id, $Permission, array('fields' => 'id','supportsTeamDrives'=>true));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.