Google云端硬盘服务帐户额外存储 [英] Google Drive Service Accounts Additional Storage

查看:141
本文介绍了Google云端硬盘服务帐户额外存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用,我的应用的用户可以上传/下载文件,我不希望他们在每次上传文件时都要进行授权。所以我才知道服务帐户是解决方案,而这正是我所期待的。我遵循本页中给出的说明:



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



这一切都很好,但问题在于限制,即仅限于5GB,没有任何方法可以为我的服务帐户购买一些额外的存储空间(据说它不能完成,但我仍然想确认)。我不想使用网络服务器流程,我保存凭证,即Access令牌,并在每次过期时刷新令牌。有没有解决我的问题的解决方案?解决方案

解决方案将文件存储在您自己的Google云端硬盘帐户中,而不是谷歌的服务驱动器帐户是授予所有者权限到您的服务帐户在您的控制台的谷歌开发。



然后在您的个人谷歌驱动器中创建一个文件夹,并获得该文件夹的ID。



当您使用服务帐户上传文件时,请务必将该文件夹的ID作为您正在上传的文件的父级ID

  $ file = new Google_Service_Drive_DriveFile(); 
$ file-> title =自动机;
$ 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);

现在您可以将文件上传到自己的Google云端硬盘而不是服务帐户云端硬盘



希望这有助于

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?

解决方案

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

这篇关于Google云端硬盘服务帐户额外存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆