Google Drive Service Accounts Additional Storage

人盡茶涼 提交于 2019-11-28 14:31:36

A solution to store files in your own google drive account rather than google drive of service account is to grant owner permission to your service account in your console of google developer.

And then create a folder inside your personal google drive and get the id for that folder.

and when you upload file using service account make sure to put id of that folder as parent id for file which you are uploading like this

$file = new Google_Service_Drive_DriveFile();
  $file->title = "Automata";
$parent = new Google_Service_Drive_ParentReference();
$parent->setId('Your Folder id');
$file->setParents(array($parent));
  $requestss = $drive_service->files->insert($file,array(
      'data' => $data,
      'mimeType' => 'application/pdf',
    ));

$permission = new Google_Service_Drive_Permission();
$permission->setRole( 'writer' );
$permission->setType( 'anyone' );
$permission->setValue( 'youraccount@gmail.com' );
$drive_service->permissions->insert( $requestss->getId(), $permission ); 

Now you will be able to upload files to your own google drive instead of service account drive

Hope this helps

Take a look at:

https://developers.google.com/drive/service-accounts

Service Accounts cannot purchase additional storage so you'll need to use a regular Google account instead.

Share your normal account's folder to your Service account.
Your service account's addresss looks like XXX@XXX.iam.gserviceaccount.com.
Then your Service account can see the shared folder from your normal account.
Now your Service Account get the Additional Storage of your normal account.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!