python - Google Drive API:用户未授予应用程序错误
问题描述
我正在关注Quickstart
https://developers.google.com/drive/api/v3/quickstart/python 上的内容。我已经通过页面启用了驱动器 API,加载了credentials.json并且可以成功列出我的谷歌驱动器中的文件。但是,当我想下载文件时,我收到了消息
`The user has not granted the app ####### read access to the file`
除了将该范围放入我的代码之外,我还需要做更多的事情还是需要激活其他东西?
SCOPES = 'https://www.googleapis.com/auth/drive.file'
client.flow_from_clientsecrets('credentials.json', SCOPES)
解决方案
一旦你经历了Quick-Start Tutorial
最初的范围,范围如下:
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
因此,在列出文件并且您决定下载之后,它将无法正常工作,因为您需要再次生成令牌,因此更改范围不会重新创建或提示您进行首次运行时发生的“谷歌授权”。
要强制生成令牌,只需删除您的当前令牌或使用新文件从存储中存储您的密钥:
store = file.Storage('tokenWrite.json')
推荐阅读
- javascript - JSON模式对象的Typescript类型
- hazelcast - 我应该在我的对象中保留对 Hazelcast Map 的引用吗?
- python - append() 在这个代码片段中是如何工作的?对特定变量感到困惑
- excel - 有没有办法循环满足条件的行以设置单个范围
- python - 无法识别 Sikuli 斜线字符(欧洲键盘)
- c# - DevExpress PieChart WebChartControl 悬停以突出显示饼图
- css - 标题在分类档案页面中显示两次
- schema - 哪种旅行/旅行体验模式?
- javascript - 错误:缺少表“脚本”的 FROM 子句条目
- php - PHP如何自动运行脚本