On the Google API explorer I tried giving the correct fileId in drive.permissions.create. I set supportsTeamDrives to true and Request body with role: reader and type: anybody. 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. 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
What I need to do is to temporarily set the permission on 20-50 files in a folder to "public" (i.e. 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. 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.
An alternative to this would be if there is some way to get the image thru a URL with the token included, e.g.
$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. 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. Is there some way to make this work? This way I wouldn't have to worry about the file permissions (back-n-forth).