2

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?

user1996298
  • 21
  • 1
  • 2

4 Answers4

0

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

gabriel garcia
  • 368
  • 3
  • 17
0

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.

drinkmystery
  • 1,476
  • 1
  • 10
  • 6
0

Take a look at Domain wide delegation. It enables service accounts to impersonate human users inside your organization and make requests in their behalf. I've had success uploading a file to a user folder inside our organization's Drive as myself, but using the service account's credentials.

https://developers.google.com/identity/protocols/oauth2/service-account#delegatingauthority

Also, if your app only manages files created by itself, avoid using the .../auth/drive scope since it's too privileged. Use .../auth/drive.file instead.

I find it sad that Google's security infrastructure is so complicated. Most web services still use regular API tokens, which I understand are strongly insecure. It's good that they're trying to raise the bar, but Google doesn't seem interested in simplifying it's documentation.

Filipe Nicoli
  • 183
  • 1
  • 8
-1

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.

Jay Lee
  • 13,415
  • 3
  • 28
  • 59
  • But for regular account, clients should be authorized to upload files right? Where the files will be stored in that case? In my account or users? – Altynbek Usenov Aug 14 '14 at 07:21