首页 > 解决方案 > Google Drive API:如何连接到“受限 API”?

问题描述

我正在尝试连接到 Google Drive V3 API:https ://www.googleapis.com/auth/drive 但根据 Google文档,此 API 访问是“受限的”。我想使用这个 API,因为这是唯一允许“查看、编辑、创建和删除所有Google Drive 文件”的 API。

然后,它说“如果您认为您的应用程序需要限制范围,请参阅请求限制范围验证和安全评估。”

之后,我确实尝试使用Whitelist connected apps中的 Step2 将我的应用程序列入白名单,但没有成功:

$ curl -d 'client_id=[$CLIENT_ID]' -d 'scope=https://www.googleapis.com/auth/drive' -d 'response_type=code' 'https://accounts.google.com/o/oauth2/device/code'
curl: (3) Illegal characters found in URL

欢迎任何建议。或者任何关于列出我所有文件的其他方法的建议也将受到欢迎。先感谢您。

标签: curlgoogle-drive-api

解决方案


显然,它有效,但我使用了错误的 cURL 命令。正确的是:

curl ^
--data client_id=%CLIENT_ID% ^
--data client_secret=%CLIENT_SECRET% ^
--data code=%AUTH_CODE% ^
--data redirect_uri=urn:ietf:wg:oauth:2.0:oob ^
--data grant_type=authorization_code ^
https://www.googleapis.com/oauth2/v4/token

推荐阅读