Google 驱动器 API - 很抱歉......但是您的计算机或网络可能正在发送自动查询

Google Drive API - We're sorry...... but your computer or network may be sending automated queries

我们有一个 Google Drive Oauth2 应用集成。我们正在使用 Google Drive API 导出和获取端点,以便从我们客户的 Google Drive 文件夹中读取数据。 我们的应用程序由 Google Oauth 验证团队发布,但我们无法读取不是(csv、xls、xlsx)Google 文档文件的文件。

这是一个 API 请求示例: URL:

"https://www.googleapis.com/drive/v3/files/1874uz4MTNer4IszgWG_3pH6VEH2AWJPd?alt=media&access_token=ACCESS_TOKEN"

回复:

"<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/><title>Sorry...</title><style> body { font-family: verdana, arial, sans-serif; background-color: #fff; color: #000; }</style></head><body><div><table><tr><td><b><font face=sans-serif size=10><font color=#4285f4>G</font><font color=#ea4335>o</font><font color=#fbbc05>o</font><font color=#4285f4>g</font><font color=#34a853>l</font><font color=#ea4335>e</font></font></b></td><td style=\"text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%\"><div style=\"border-bottom: 1px solid #dfdfdf;\">Sorry...</div></td></tr></table></div><div style=\"margin-left: 4em;\"><h1>We're sorry...</h1><p>... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.</p></div><div style=\"margin-left: 4em;\">See <a href=\"https://support.google.com/websearch/answer/86640\">Google Help</a> for more information.<br/><br/></div><div style=\"text-align: center; border-top: 1px solid #dfdfdf;\"><a href=\"https://www.google.com\">Google Home</a></div></body></html>"

同样的请求在 2020 年 2 月 7 日之前都运行良好。

使用导出 Google Doc 文件的导出端点,工作正常。

第一时间,我们发现这个 link 描述了一些变化:https://support.google.com/cloud/answer/9110914 我们申请了 Oauth 验证,我们已经通过了,但我们仍然看到同样的问题,即使我们重做 Oauth2 身份验证流程生成新的 Access/Refresh 令牌。 我们已经尝试在 Issue Tracker 和 Oauth Team 上就此联系 Google,但都无济于事。 我们在生产服务器上没有任何类型的恶意软件、VPN,或者我们可以在一些相关问题中找到的任何类似的东西。

有人对如何解决这个问题有什么建议吗?

谢谢。

我们遇到了同样的问题,经过一些测试,我们发现 Google 似乎正在更彻底地检查令牌的来源。

根据https://developers.google.com/drive/api/v3/about-auth

  1. If the user approves, then Google gives your application a short-lived access token.
  2. Your application requests user data, attaching the access token to the request.
  3. If Google determines that your request and the token are valid, it returns the requested data.

我们使用的是 JS 文件选择器,在收到对象数据后,当我们尝试 $.get 它时,文件已正确下载,但相同的 URL 其他任何地方都返回错误.

更新

我们再次使用 https://developers.google.com/drive/api/v3/manage-downloads:

To download a file stored on Google Drive, use the files.get method with the ID of the file to download and the alt=media URL parameter. The alt=media URL parameter tells the server that a download of content is being requested.

我们设法让它再次运行。我们发现了这个:https://cloud.google.com/blog/products/application-development/upcoming-changes-to-the-google-drive-api-and-google-picker-api

Google 没有更新他们的云端硬盘 API 文件,所以我们不知道这个变化。

基本上我们必须从 access_token URL 参数切换到授权 Header。也就是说,要验证 API,您应该像这样使用 Header:

"Authorization" : "Bearer ACCESS_TOKEN"

这对我们有用。

谢谢大家的帮助。