5
votes

The Google Drive API GET query started to fail (we are using this api in one of our client service):

https://www.googleapis.com/drive/v3/files/1ke4Yoxxxxxxxxxxxxxx?alt=media&access_token=ya29.ImG9BwT.....

We're sorry... ... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now. See Google Help for more information... "Unusual traffic from your computer network"

Everything was ok till today.

Just made a couple of tests with curl:

  1. HTTP GET with access_token inside HTTP header: curl -H "Authorization: Bearer ya29._valid_access_token" https://www.googleapis.com/drive/v3/files/1r5BT2WPrulQ6FyhT8RcqV51TVOThEmhK?alt=media

Result: success, file downloaded.

  1. HTTP GET with access_token as a part of HTTP request: curl https://www.googleapis.com/drive/v3/files/1r5BT2WPrulQ6FyhT8RcqV51TVOThEmhK?alt=media&access_token=ya29._valid_access_token

Result: error

    {
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued       use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
} 

Note that the Google API project approved by Google and has a Production state!!!

Hi Google team, any ideas why it is happening?

Thank you

2
I think that the reason of your issue is due to this. Unfortunately, the query parameter of access_token cannot be used. So please use the access token to the request header instead of the query parameter. - Tanaike
Yes, that is the case. - P.Filippov
Yes, that is the case. Unfortunately, Google didn't update these docs: developers.google.com/drive/api/v3/query-parameters You can provide an OAuth 2.0 token with any request in one of two ways: 1. Using the access_token query parameter like this: ?access_token=oauth2-token 2. Using the HTTP Authorization header like this: Authorization: Bearer oauth2-token - P.Filippov
I'm voting to close this question as off-topic because it is a question for Google support, clearly. - TylerH
I faced a similar problem using googleapis , when I updated the package from 39 to 48 the problem solved. - karianpour

2 Answers

4
votes

Posting this just for documentation purposes. As per the reference provided by Tanaike, since January 1, 2020:

download calls to files.get, revisions.get and files.export endpoints which authenticate using the access token in the query parameter will no longer be supported.

Only requests that download media content (alt=media) are affected by this change.

The access token should be provided in the HTTP header, like Authorization: Bearer oauth2-token or, if that's not possible, follow the workarounds provided in the referenced documentation:

For file downloads, redirect to the webContentLink which will instruct the browser to download the content. If the application wants to display the file to the user, they can simply redirect to the alternateLink in v2 or webViewLink in v3.

For file exports, redirect to the export link in exportLinks with the desired mime type which will instruct the browser to download the content.

Reference:

2
votes

Posting an addition to the documentation of iamblichus specific for application data in Google Drive.

My App uses the Google Drive API in the backend to store the documents of my users on their own Drive. Importantly, I store the data in an application data folder such that the users can't accidently delete the data.

To let the users retreive their documents I used to redirected the user to the downloadUrl: https://www.googleapis.com/drive/v2/files/id?alt=media&source=downloadUrl&access_token=ya29.** where I added alt=media and access_token to the query. This worked fine till January 1, 2020. As confirmed above. However, now the request fails with the message:

We're sorry... ... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.

GET request downloadUrl failing

In my efforts to find a solution to this problem I've tried the workarrounds provided by Google but they are in my experience not working for documents in an application data folder.

I tried the webContentLink with the access_token query in v2 but it fails with an 401 Unauthorized error.

The alternateLink in v2 and the webViewLink in v3 fail with the error:

The desired file does not exist.

I can't use the exportLinks because that's only for Google Documents.

The solution I found was to first download the file to the server using the Google Drive PHP SDK and then serve it to my users using a Content-Dispostion header. Such as described here. It is a lot less elegant in my opinion because the end users doesn't download the document directly from the Google Drive API but it works.

It's a shame that Google didn't update their documentation nor notified their users..