未授予Google云端硬盘API的读取访问权限

时间:2018-11-18 14:03:50

标签: 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

1 个答案:

答案 0 :(得分:1)

取决于范围。您只授予了metadata.readonly访问权限

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


Google Drive API Authorizations

enter image description here