【发布时间】:2018-07-17 05:00:24
【问题描述】:
假设有三个步骤,
- 获取设备代码,
- 获取身份验证令牌,
- 连接到 Google 云端硬盘。
第 1 步:
如果(且仅当)我忽略了在各种操作方法链接上列出的必要的 redirect_url 参数,我将通过第 1 步。所以...
curl -d 'client_id=*client_id*' -d 'scope=https://www.googleapis.com/auth/drive.file' -d 'response_type=code' 'https://accounts.google.com/o/oauth2/device/code'
那时回报是...
{"device_code": "[device_code]", "user_code": "[user_code]", "expires_in": 1800, "interval": 5, "verification_url": "https://www.google.com/device"}
到目前为止一切顺利。
第 2 步: 这就是我卡住的地方。尝试了以下各种迭代:
curl -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id=**client_id**' -d 'client_secret=*client_secret*' -d 'grant_type=authorization_code' -d 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -d 'code=[device_code_from_above]' 'https://accounts.google.com/o/oauth2/token'
以上返回
{"error" : "invalid_grant", "error_description" : "Malformed auth code."}
如果grant_type 更改为'http://oauth.net/grant_type/device/1.0',则响应为
{"error" : "invalid_request", "error_description" : "Parameter not allowed for this message type: redirect_uri"}
如果redirect_uri 被删除,则响应为
{"error" : "authorization_pending"}
上面的 cURL 尝试是参考以下链接拼凑在一起的... https://developers.google.com/identity/protocols/OAuth2ForDevices
http://www.visualab.org/index.php/using-google-rest-api-for-analytics#comment-157284
list google drive files with curl
Google Drive not listing files in folder
Not able to fetch Google OAuth 2.0 access token
https://www.daimto.com/google-authentication-with-curl/
受阻!
编辑
根据请求,这里的目标是:开发一种在文件上传时收到警报的方法,并建立一个可以根据各种查询有选择地、系统地下载的系统。
我们不使用 Google Drive 的 Web UI 执行此操作的原因:文件大小非常大:每个文件 10-50gb,而且 Google 无法在不先压缩的情况下批量下载,并且无法压缩超过大小的任何内容这比我们最小的文件还小。
我们不使用 Google Drive 的 APP 执行此操作的原因:无法 (AFAIK) 管理哪些文件可以在本地下载和不可以在本地下载,并且无法(再次 AFAIK)存储到外部卷。
此外,我们正在将工作流数据库集成到我们的媒体上传和下载中:跟踪、日期、进度说明、版本等,这些都不属于任何现有的 Google 系统。所以这里的目标是看看 Google 的 API 可以为这一切提供哪些选项。
【问题讨论】:
-
您究竟要粘贴到“device_code_from_above”中的内容。出于安全考虑,请随意混淆实际代码值。它应该类似于“4/AADhY_JAsynoD1SEAMbmt-oVmO_kWbFJ_XV3qap7XVd7iAmpjrgkOa5kAefLEpl38pcKEBXIOxQ568q_kzU”
-
第 1 步将“device_code”作为 98 个字符的字符串返回,该字符串之前以“4/AA”开头,最近以“AH-1N”开头。
-
"AH..." 不是验证码,因此出现错误。您确定要取消测试运行之间的授权,并且您是否将设备代码与 Auth 代码混淆了。
-
可能值得更新您的问题以解释您的方案以及您希望实现的目标。没有浏览器就无法授权 API/应用程序,因为在用户授权之前,他必须首先通过 Google 网络登录和会话 cookie 进行身份验证。
标签: curl oauth google-drive-api google-oauth