【问题标题】:Google Drive API read access not granted未授予 Google Drive API 读取权限
【发布时间】:2018-11-18 14:03:49
【问题描述】:

我正在尝试使用 Google Drive API 从 Google Drive 下载一个随机文件。虽然在运行代码后我收到一条错误消息:用户尚未授予应用程序(app_code)对文件(文件名)的读取权限。如何授予对文件的读取权限?我在 Internet 上以及 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

【问题讨论】:

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


【解决方案1】:

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

改成 'https://www.googleapis.com/auth/drive.readonly'


Google Drive API Authorizations

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    相关资源
    最近更新 更多