Google Drive Service Accounts Additional Storage

后端 未结 3 1093
天涯浪人
天涯浪人 2020-12-12 05:17

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 Acco

相关标签:
3条回答
  • 2020-12-12 05:28

    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.

    0 讨论(0)
  • 2020-12-12 05:28

    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.

    0 讨论(0)
  • 2020-12-12 05: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

    0 讨论(0)
提交回复
热议问题