(403) The user has exceeded their Drive storage quota ph - google-drive-api

We have Google Drive account and using Google Console we created Service Admin Account which has access to folders in our Drive. Our Drive storage went out of space so application which was sending new files to Google Drive started to fail with error in the title.
We have added 100GB new storage(on Drive via Google One) but application still fails and responds with this error message.
As far as I investigated Service Accounts only have limited space so this account still has no space left even though my real account has 100GB more.
I tried to transfer ownership of folder in Drive to Service Account but I couldnt because I need to accept that and I cannot log into Service Account.
This project is old and uses google-api-php-client to connect to Drive and do other stuff.
Any help is appreciated!
EDIT: Hitting https://www.googleapis.com/drive/v2/about endpoint with same credentials as Service Account used to send files to Drive gives me this information about quota.
"quotaBytesTotal": "107374182400",
"quotaBytesUsed": "84631990",
"quotaBytesUsedInTrash": "1573901",
Which is not logical to me because there is actually free space to be used.

I have a potential idea on the issue and clarification about the scenario. Based on the fact that you do not have a Google Workspace account to work with the Service account, you could be affected by the recent workflow changes on how the transfer of ownership of files between Google Accounts.
Important notes:
Service accounts are basically Google Accounts with their own default Drive Storage, 15 GB as any free Gmail account.
You cannot increase the storage for the Service accounts.
If you are sending the files to a Personal account, and the new workflow could be blocking it or delaying the process. Which could explain the error of space, it is not the personal account with the extra 100 gb, it is the Service account, because the file never changes the ownership.
There is an Feature request that you can send also the feedback, and a similar scenario as yours has been shared by other people.
The Google Drive API, has updated some of the process but they mostly applied to Google Workspace account, you can review it here.

Related

Cannot Get Total Shared Drive Size using Google Drive API

We use the Drive API in a few scripts to get info on all our Shared Drives. Using the “useDomainAdminAccess” parameter in the drives list/get methods, we can get just about all drive details without adding the script account as owner on the target drives. One detail we cannot get using this method is total drive size. It appears there is no native property for drive size when querying details at the drive level. We can get a size param when querying individual files (but we must add the script account as an owner on the drive).
In summary, to get drive size we must add the script account as an owner on the drive. Then iterate through all files within the drive, getting the size param for each and adding it to a global variable which we return as total drive size at the end of the iteration. After this we remove the script account from the drive. This, of course, seems very inefficient for getting a single property. Do we know if Google plans to include a size param within the drives.list/drives.get api, or add the “useDomainAdminAccess” param to the files.list/files.get api or maybe there is another Google API that can provide this detail with less effort (reporting / gws admin api)? Thanks
https://developers.google.com/drive/api/v3/reference/drives/list
https://developers.google.com/drive/api/v3/reference/files/list
You may benefit from filing a feature request on Google's Issue Tracker and provide all the necessary details there.
I suggest you fill in this template here.
As for an alternative for your current workaround, I suggest you take a look at service accounts and domain-wide delegation in order to impersonate the owner of the drive and perform the request on their behalf.
A service account is a special kind of account used by an application or a virtual machine (VM) instance, not a person. Applications use service accounts to make authorized API calls.
Reference
Service Accounts;
Drive API Perform Google Workspace Domain-Wide Delegation of Authority.

Gdrive API error 403 for transferring ownership "Rate limit exceeded. User message: "Sorry, you have exceeded your sharing quota."

There is no documentation on any sharing quota. My limited understanding based on some searches is that it's in place to prevent some kind of spamming.
Google will not let a user transfer ownership of a file outside of the domain in which it is already owned, so I'm obviously not spamming people in my own private Gsuite domain.
Is there a way to lift this restriction? Is there any documentation on this?
As stated by this documentation here:
A sharingRateLimitExceeded error occurs when the user has reached a sharing limit. This error is often linked with an email limit.
In order to fix the error, you can try the following:
Do not send emails when sharing lot of files.
If one user is making a lot of requests on behalf of many users of a G Suite domain, consider a Service Account with authority delegation to impersonate the owner of each document to share (setting the quotaUser parameter).
Moreover, you can check the status of your quota for the Drive API by accessing the Google Cloud Project for it and checking the Quotas section:
Reference
Google Drive API Resolve Errors;
Using OAuth 2.0 for Server to Server Applications;
Viewing your Quota

Service account on Drive API has reached the storage limit

Is there a way I can remove data from a Service account created for a Project for Drive API since this is hitting the storage limit. Can I transfer the data to another non service account, Or can I substitute this service account for another? so I can keep using my project or shall I create a new project and integrate it with a new Service account?
Possible solutions seem are described on these other questions, but I´m not sure yet about the solution.
Google Drive Service Accounts Additional Storage
Quota, orphaned files and uploads using service account with Google Drive API
Google Drive API ownership of files uploaded from service account
Google APPs managed "unlimited" account storage quota for service account
Can you please help?
As far as I know, Service Accounts currently cannot purchase additional storage so if you want more storage, you'll need to use a regular Google account instead. Aside from that, change of ownership of service account files is also not possible with Google Drive API.
The only possible option that I found, for now, is to transfer the ownership of the service account file to another account via the app script given in SO post - How to use a service account to transfer ownership of a google file.
After transferring of file ownership, to keep using your project, you can grant owner permission to your service account in the drive file that you need to access by sharing the document.
Solution given by Jalogar in SO post - Drive API access to document with service account might really help.

Google Drive & Service Account Storage Limit/Quota

for my Google App Engine application I would like to use the Service Account's own Google Drive, i.e. I do not wish to create a "regular" gmail account and grant privileges to my Service Account, nor I want to share files with anyone else, I just wish to use the Drive as a "internal filesystem" for the application, accessed by the application only.
My questions:
1) is such service still provided, i.e. are Service Accounts granted to use their own private Drive, or am I forced to use the "new" Google Cloud Storage?
2) where can I find any relevant & updated information regarding the storage quota for such Drive & possible options for expanding it? I browsed many forums, but all posts I found (including on SO) contains dead links and/or states various information ("I think its 5 GB", "I believe its 15 GB" etc.)
Thanks in advance to anyone who can unravel the mystery :-)
You can use the Drive resource about.get and find all the information related to your Drive.
If you make the call from your service account, you can know what is the total amount of available space returned in the parameter quotaBytesTotal for that account.
I just checked and for me it was 15 GB, so that's likely the same available space you will get.

Store file on google drive from server

I 've the follow simple scenario:
a server of my boss
some costumers with google drive accounts
so I'd like to transfer daily some files to costumers google drive...
My question is: if a customer have pc disconnected or is not logged to my site is possible from my server upload a file into costumer google drive?
And if yes there's a limit of user or daily transfer?
p.s.
better if I can use A Google Drive spreadsheet and update data
thanks
Yes it is possible, but there are many steps in between.
1.- You would need an application, so you can perform this operations through your app. check the documentation.
2.- You would need to set the offline access, this way you will be able to upload files even if the user is not logged. Oauth Offline access.
3.- The users (customers with Google Drive account) will have to authorize your application to access their Drive accounts. After this you will be able to get an access token and a refresh token.
4.- With the refresh token you can refresh the access token (it expires after an hour) without having the user to login again and get a new access token. (you have to store this refresh token)
5.- Now you can call the function Drive.Files.Insert in order to upload a file into the customer's Drive. When calling this function you need to provide the access token related to the user.
6.- There are limits that apply to the API. These quotas are against the application. If you make too many calls to the API, you may reach these limits for your application. You can check these limits in the Developer Console of your application.
I hope this helps. I know it's a lot of information but is the procedure you need to follow.