Google云端硬盘API:用户未授予应用错误 [英] Google Drive API: The user has not granted the app error

查看:387
本文介绍了Google云端硬盘API:用户未授予应用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 https://developers.google上的Quickstart .com/drive/api/v3/quickstart/python .我已经通过页面启用了驱动器API,并加载了 credentials.json 并可以成功列出Google驱动器中的文件.但是,当我要下载文件时,收到消息

I'm following the Quickstart on https://developers.google.com/drive/api/v3/quickstart/python. I've enabled the drive API through the page, loaded the credentials.json and can successfully list files in my google drive. However when I wanted to download a file, I got the message

`The user has not granted the app ####### read access to the file`

除了将作用域放入代码中还是需要做更多的事情吗?

Do I need to do more than putting that scope in my code or do I need to activate something else?

SCOPES = 'https://www.googleapis.com/auth/drive.file'
client.flow_from_clientsecrets('credentials.json', SCOPES)

推荐答案

一旦您完成Quick-Start Tutorial的操作,其作用域即为:

Once you go through the Quick-Start Tutorial initially the Scope is given as:

SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'

因此,列出文件并决定下载后,它将无法正常工作,因为您需要再次生成令牌,因此更改范围不会重新创建或提示您输入首次运行的"Google授权".

So after listing files and you decide to download, it won't work as you need to generate the the token again, so changing scope won't recreate or prompt you for the 'google authoriziation' which happens on first run.

要强制生成令牌,只需删除您的当前令牌或使用新文件从存储中存储密钥:

To force generate the token, just delete your curent token or use a new file to store your key from the storage:

store = file.Storage('tokenWrite.json')

这篇关于Google云端硬盘API:用户未授予应用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆