"Insufficient Permission: Request had insufficient authentication scopes" 即使是最一般的范围
"Insufficient Permission: Request had insufficient authentication scopes" even with most gerneral scope
我正在尝试从我的 google 驱动器下载电子表格。我正在关注 this reference and having problems with permission. I've started with https://www.googleapis.com/auth/drive.file 并得到了这个
"Insufficient Permission: Request had insufficient authentication scopes."
通读the permission documentation one reads the following for https://www.googleapis.com/auth/drive。
Full, permissive scope to access all of a user's files, excluding the Application Data folder.
但即使使用这个范围,我仍然收到相同的错误消息。
我的代码是这样的
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))
"Insufficient Permission: Request had insufficient authentication scopes."
表示您当前使用的登录凭据不包含足以使用您当前调用的方法的范围。
虽然您的代码似乎正在使用 https://www.googleapis.com/auth/drive
的范围,但足以使用 Files.export.
我怀疑发生的事情是你已经验证了你的用户登录并授予了对不同范围的访问权限(可能是只读的),然后更改你的代码以包含更高级别的范围并忘记要求你是代码 re-authenticate 您的用户,因此您当前 运行 的授权访问将不起作用。
您需要使用这个新范围验证您的代码。
我正在尝试从我的 google 驱动器下载电子表格。我正在关注 this reference and having problems with permission. I've started with https://www.googleapis.com/auth/drive.file 并得到了这个
"Insufficient Permission: Request had insufficient authentication scopes."
通读the permission documentation one reads the following for https://www.googleapis.com/auth/drive。
Full, permissive scope to access all of a user's files, excluding the Application Data folder.
但即使使用这个范围,我仍然收到相同的错误消息。
我的代码是这样的
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))
"Insufficient Permission: Request had insufficient authentication scopes."
表示您当前使用的登录凭据不包含足以使用您当前调用的方法的范围。
虽然您的代码似乎正在使用 https://www.googleapis.com/auth/drive
的范围,但足以使用 Files.export.
我怀疑发生的事情是你已经验证了你的用户登录并授予了对不同范围的访问权限(可能是只读的),然后更改你的代码以包含更高级别的范围并忘记要求你是代码 re-authenticate 您的用户,因此您当前 运行 的授权访问将不起作用。
您需要使用这个新范围验证您的代码。