Can you please help me with this ?
I am using PHP GOOGLE API V2.2.2
My code works using a gserviceaccount created for it, BUT, when I am trying manipulate the files on my personal GOOGLE DRIVE I have this error...
I tried following the steps shown here: Github issue 801
It went just fine and my project is shown on my authorized client list
Here is my code to create a folder inside my google drive:
function NovaPasta() {
require_once APPPATH . 'third_party/google-api-php-client-2.2.2/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS='. APPPATH . 'third_party/google-api-php-client-2.2.2/Asist-428f3540df9a.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
//$client->setAuthConfig(APPPATH . 'third_party/google-api-php-client-2.2.2/Asist-428f3540df9a.json');
$client->addScope("https://www.googleapis.com/auth/drive");
$client->setSubject('[email protected]');
$driveService = new Google_Service_Drive($client);
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'new folder name',
'mimeType' => 'application/vnd.google-apps.folder'));
$file = $driveService->files->create($fileMetadata, array(
'fields' => 'id'));
printf("Folder ID: %s\n", $file->id);
}
Here is the error:
An uncaught Exception was encountered Type: Google_Service_Exception
Message: { "error": "unauthorized_client", "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested." }