Robert Cooper Robert Cooper - 4 months ago 29x
PHP Question

File not visible in Drive after API upload and inserting permissions using php

I'm crowbarring the google api into a laravel app.

The file appears to upload correctly but remains invisible in the Drive GUI.

Many searches later and I've got this code to set the permissions of the newly created file:

$id = id of created file
$value = '';
$type = "anyone";
$role = "writer";
$drive->insertPermission($id, $value, $type, $role);

function insertPermission($fileId, $value, $type, $role) {

$service = $this->service;
$newPermission = new \Google_Service_Drive_Permission();

try {
return $service->permissions->create($fileId, $newPermission);
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
return NULL;

This seems to work. No errors are thrown. But I still can't see the file when I search in my drive. Any ideas?


As pushpendra pointed out I need to change

$type="anyone"; to $type="user"; 
$role="writer"; to $role="reader";

Also - in the end I solved this by creating a folder in the drive UI and sharing that folder with the service account. The service account is able to create/update files in that shared folder and I get a notification when it does so.