Python 未授予Google Drive API读取访问权限
我正在尝试使用GoogleDrive API从GoogleDrive下载一个随机文件。虽然在运行代码后,我收到了一条错误消息:用户没有授予应用程序(应用程序代码)对文件(文件名)的读取权限。如何授予文件的读取权限?我在互联网上和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
# 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“
也许您可以查看有关管理共享的内容。您还可以查看,以了解有关权限和角色的其他详细信息以及。