python - 未授予 Google Drive API 读取权限

标签 python python-3.x google-api google-drive-realtime-api

我正在尝试使用 Google Drive API 从 Google Drive 下载随机文件。尽管运行代码后我收到一条错误消息:用户尚未授予应用程序(app_code)对文件(文件名)的读取权限。如何授予该文件的读取权限?我在互联网上和 API 仪表板中都没有找到任何内容。

 # Call the Drive v3 API
    results = service.files().list(
        pageSize=1000, fields="nextPageToken, files(id, name)").execute()
    items = results.get('files', [])
    rand_item = random.choice(items)
    print('{0} ({1})'.format(rand_item['name'], rand_item['id']))
    if not items:
        print('No files found.')
    else:
        request = service.files().get_media(fileId=rand_item['id'])
        fh = io.BytesIO()
        downloader = MediaIoBaseDownload(fh, request)
        done = False
        while done is False:
            status, done = downloader.next_chunk()
            print("Download %d%%." % int(status.progress() * 100))

完整代码:Pastebin

最佳答案

这是由于范围造成的。您只授予了metadata.readonly 访问权限

将其更改为 'https://www.googleapis.com/auth/drive.readonly'


Google Drive API Authorizations

enter image description here

关于python - 未授予 Google Drive API 读取权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53361744/

相关文章:

python - 使用来自 (x,y,value) 三元组的数据创建 Numpy 二维数组

python - SQLAlchemy "excluded"插入中的 PostgreSQL 命名空间...冲突

php - Google Cloud API - 应用程序默认凭据

api - 使用api发送gmail附件失败

python - 确定性 python 脚本以非确定性方式运行

python - 如何在 xls 末尾跳过 pandas 数据框中的行

python - Django: AttributeError: 'Employee' 对象没有属性 'current_hours'

python - 如何在 Kivy 中更改小部件颜色

python - 使用 utf-8 字符作为诅咒边框

javascript - Google Calendar API - 如何使用 JavaScript 创建快速添加事件?