【发布时间】:2020-11-29 14:30:09
【问题描述】:
我正在尝试从我的 Google 云端硬盘下载电子表格。我正在关注this reference 并且遇到了许可问题。我从https://www.googleapis.com/auth/drive.file 开始并得到了这个
"Insufficient Permission: Request had insufficient authentication scopes."
通过the permission documentation阅读以下内容为https://www.googleapis.com/auth/drive。
访问所有用户文件的完整许可范围,不包括应用程序数据文件夹。
但即使使用此范围,我仍然收到相同的错误消息。
我的代码是这样的
import io
import pickle
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.http import MediaIoBaseDownload
file_id = "FILE ID"
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/drive']
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
service = build('drive', 'v3', credentials=creds)
request = service.files().export_media(fileId=file_id, mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
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))
【问题讨论】:
-
删除
token.pickle并重新进行身份验证时会发生什么?
标签: python google-api google-drive-api google-oauth google-api-python-client