I have the following situation, I am using the Google Driver API from my php to upload files from my system. What is happening to me is that it generates a permission error when executing the script when I go to upload the file. I verified my token and it tells me that it has not expired yet. Below I leave the error, the result of the token and the code that I am using to see if you can help me.
Thanks.
Token
{
"issued_to": "569124525622-smkdbucj6bj8t87ptisvd2sdma3v747o.apps.googleusercontent.com",
"audience": "569124525622-smkdbucj6bj8t87ptisvd2sdma3v747o.apps.googleusercontent.com",
"scope": "https://www.googleapis.com/auth/drive.metadata.readonly",
"expires_in": 1512,
"access_type": "offline"
}
error being generated
Fatal error: Uncaught exception 'Google_Service_Exception' with message ' in /opt/lampp/htdocs/gdriver/vendor/google/apiclient/src/Google/Http/REST.php on line 118
Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission" } ], "code": 403, "message" : "Insufficient Permission" } } in /opt/lampp/htdocs/gdriver/vendor/google/apiclient/src/Google/Http/REST.php on line 118
My code
require __DIR__ . '/vendor/autoload.php';
$client = getClient();
$service = new Google_Service_Drive($client);
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'sql_query.jpg'));
$content = file_get_contents('files/sql_query.jpg');
$file = $service->files->create($fileMetadata, array(
'data' => $content,
'mimeType' => 'image/jpeg',
'uploadType' => 'multipart',
'fields' => 'id'));
printf("File ID: %s\n", $file->id);
You are passing a wrong scope, according to the documentation , to create use
create
infiles
you need at least one of these scopesYou are even passing read-only scopes, add some of those scopes to your
client