Error with google driver api

0

I have the following situation, I am using the API of Google Driver 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 upload the file. Check my token and tell me it has not expired yet. Then I leave the error, the result of the token and code that I am using to see if they can help me.

Thank you.

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 that is 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);
    
asked by Yoel Rodriguez 23.10.2018 в 01:01
source

1 answer

1

You are passing an incorrect scope, according to the documentation , to create use create in files need at least one of these scope

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

You're even going through read-only scopes, add some of those scope to your client

    
answered by 23.10.2018 / 01:49
source