I would like to add a file in my Google Drive with the php API. I correctly set the service account permissions in the google console and also in google admin. My code is as follows :
$client = new Google_Client();
$client->setAuthConfig('path.json');
$client->addScope('https://www.googleapis.com/auth/drive');
$service = new Google_Service_Drive($client);
//Insert a file
$fileMetadata = new Google_Service_Drive_DriveFile(array('name' => 'test.txt'));
$content = file_get_contents('test.txt');
$file = $service->files->create($fileMetadata, array( 'data' => $content, 'mimeType' => 'text/plain', 'uploadType' => 'multipart', 'fields' => 'id'));
print($file->id);
It returns the id : 1otqEi5qaJ8SDjcPMIFOWtMQVPXZKlaSb But the document is not present on my drive...
Thank's for help...
A service account is NOT you. A service account has its own google drive account. The file is being uploaded to its google drive account.
If you want it to upload to your google drive account then take the service account email address add share a directory in your google drive account with it. Then take the file id / drive id of that folder and set it as the parent in the file metadata when you upload the file and it will be uploaded to your drive account and not the service accounts.
remember to have the service account grant you permissions on that file after its been uplaoded the file will be owned by the service account.