Am trying to set google drive permission on a file via Curl in PHP.
google drive API
Here is API Sample Data
POST https://www.googleapis.com/drive/v3/files/FILE_ID/permissions
{
"requests": [
{
"type": "user",
"role": "commenter",
"emailAddress": "[email protected]"
}
]
}
Below is my sample code.
$access_token = 'xxxxxxxxxxxxxx';
$file_id = 'xxxxxxxxxxxxxx';
$headers = array(
"Authorization: Bearer $access_token"
);
$post_fields = '{
"requests": [
{
"type": "anyone",
"role": "reader"
}
]
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/$file_id/permissions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
echo $response = curl_exec($ch);
var_dump($response);
Here is the error it throws
{ "error": { "code": 400, "message": "The permission type field is required.", "errors": [ { "message": "The permission type field is required.", "domain": "global", "reason": "required", "location": "permission.type", "locationType": "other" } ] } } string(323) "{ "error": { "code": 400, "message": "The permission type field is required.", "errors": [ { "message": "The permission type field is required.", "domain": "global", "reason": "required", "location": "permission.type", "locationType": "other" } ] } } "
it seems this permmission request data below is not properly passed in the API. Can someone help me out.
{
"requests": [
{
"type": "anyone",
"role": "reader"
}
]
}