Google Drive Service Accounts Additional Storage

2019-01-20 17:02发布

问题:

I have an app where the users of my app can upload/download files, I don't want them to authorize every time they want to upload a file. So I came to know that Service Account is the solution to it, and that is exactly what I was looking for. I followed the the instructions given in this page:

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

It all works good, but the problem is the limit, i.e only 5GB, Isn't there any way where I can buy some Additonal Storage for my service Account(It is mentioned that It cannot be done, but still I just want to confirm). I do not want to use the web-server flow, where I save the credentials i.e Access Token and refresh the token every time it expires. Is there any solution to my problem?

回答1:

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



回答2:

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.



回答3:

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.