【发布时间】:2018-12-25 20:18:56
【问题描述】:
使用 Google Drive 的 API,我可以获得授权和令牌,但在尝试获取文件列表时,API 当前仅返回一个项目:名为“Getting Started”的 PDF。据推测,这是刚刚建立的 Google Drive 中的默认项目——该项目早已从我们正在使用的预期 Google Drive 帐户中删除。
同时使用 API Explorer (https://developers.google.com/apis-explorer) 返回数百个项目,这些项目实际上代表相关帐户的 Google Drive。
API Explorer 说它发送的请求是:
GET https://www.googleapis.com/drive/v3/files?corpus=user&pageSize=100&key={YOUR_API_KEY}
发送直接返回“权限不足”错误,这是有道理的:它是 api_key,而不是 access_token
将&key= 与&access_token= 切换确实会返回一个文件列表,但其中唯一的项目是上面提到的“入门”PDF。
API 和 Explorer 之间的差异给人的印象是……
a) 每个都引用不同的帐户,或
b) API 控制台 (https://console.developers.google.com) 中授予的权限/范围/访问权限比资源管理器窄
关于 a) 每个都引用不同的帐户:不太可能。这些凭据都是在登录到用于运行 API Explorer 的同一 Google 帐户时在 API 控制台中创建的。
关于 b) 权限/范围/访问在某种程度上有所不同:可能性更大,但目前尚不清楚如何或如何调整以产生影响。
发送的 cURL 调用:
curl https://www.googleapis.com/drive/v3/files?corpus=user&pageSize=100&key={YOUR_API_KEY} (NG. Needs a token)
curl https://www.googleapis.com/drive/v3/files?corpus=user&pageSize=100&access_token={recently_obtained_token} (this works, but returns only one item -- the "Getting Started" PDF)
回归:
{"kind": "drive#fileList", "incompleteSearch": false, "files": [{"kind": "drive#file", "id": "XXXX", "name": "Getting started", "mimeType": "application/pdf"}]}
此处列出了用于达到此目的的授权和令牌步骤... How to connect to the Google Drive API using cURL?
根据这篇文章 (Access Google Drive API Returns Empty File List)
使用的范围确实是https://www.googleapis.com/auth/drive
在同一链接下,kvzrock 的一个答案建议给予“服务帐户电子邮件地址的许可”
几个链接:
Google Drive API, Oauth and service account
How do I authorise an app (web or installed) without user intervention?
但是还不能理解这些。
【问题讨论】:
标签: curl google-api google-drive-api service-accounts