Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未授予Google Drive API读取访问权限_Python_Python 3.x_Google Api_Google Drive Realtime Api - Fatal编程技术网

Python 未授予Google Drive API读取访问权限

Python 未授予Google Drive API读取访问权限,python,python-3.x,google-api,google-drive-realtime-api,Python,Python 3.x,Google Api,Google Drive Realtime Api,我正在尝试使用GoogleDrive API从GoogleDrive下载一个随机文件。虽然在运行代码后,我收到了一条错误消息:用户没有授予应用程序(应用程序代码)对文件(文件名)的读取权限。如何授予文件的读取权限?我在互联网上和API仪表板上都没有找到任何东西 # Call the Drive v3 API results = service.files().list( pageSize=1000, fields="nextPageToken, files(id, na

我正在尝试使用GoogleDrive API从GoogleDrive下载一个随机文件。虽然在运行代码后,我收到了一条错误消息:用户没有授予应用程序(应用程序代码)对文件(文件名)的读取权限。如何授予文件的读取权限?我在互联网上和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))

完整代码:

其原因在于范围。您只授予metadata.readonly访问权限

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



也许您可以查看有关管理共享的内容。您还可以查看,以了解有关权限和角色的其他详细信息以及。