I'm working on a PHP application where users are allowed to create folders on Google Drive via the application. I can't see the folders being created from the application. I've already tried this answer. The service account was set to owner (full access) and I thought that the service account being set to this would allow anyone using the application would at least have writer, commenter, and reader rights. I tried the above answer, but I was only able to print out this:
Google_Service_Drive_Permission Object ( [collection_key:protected] => teamDrivePermissionDetails [allowFileDiscovery] => [deleted] => [displayName] => [domain] => [emailAddress] => [expirationTime] => [id] => 16863121739429784266 [kind] => drive#permission [photoLink] => [role] => writer [teamDrivePermissionDetailsType:protected] => Google_Service_Drive_PermissionTeamDrivePermissionDetails [teamDrivePermissionDetailsDataType:protected] => array [type] => user [internal_gapi_mappings:protected] => Array ( ) [modelData:protected] => Array ( ) [processed:protected] => Array ( ) )
SetValue() doesn't seem to be used with Google API v3, instead used the setEmailAddress(). I know that I've accessed the Drive API by looking at the Developer Console Resource Graph and I can see spikes whenever I request a resource.
I'm not getting an error, and I can also see the File/Folder ID, I'm just not seeing the newly created folders in the Drive. What else can it be? Could someone just point me in the right direction?
My code is below:
$client = new Google_Client();
$client->setAccessToken($result); //$result holds the token, using JWT
$service = new Google_Service_Drive($client);
//Insert a file
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'window',
'mimeType' => 'application/vnd.google-apps.folder'));
$file = $service->files->create($fileMetadata, array(
'fields' => 'id'));
printf("Folder ID: %s\n", $file->id);
$fileId = $file->id;
$newPermission = new Google_Service_Drive_Permission();
$value="createfolder@dummydocs.iam.gserviceaccount.com";
$type="user";
$role="writer";
$newPermission-> setEmailAddress($value);
$newPermission->setType($type);
$newPermission->setRole($role);
try {
$res= $service->permissions->create($fileId, $newPermission);
print_r($res);
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}