【发布时间】:2020-06-27 11:46:08
【问题描述】:
我创建了Service Account Credentials here 并得到了json key service.json。
然后我尝试了:
from google.oauth2 import service_account
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
credentials = service_account.Credentials.from_service_account_file(
'service.json', scopes=SCOPES)
drive = build('drive', 'v3', credentials=credentials)
file_metadata = {
'name': 'sampleName',
'parents': ['#### folderId ###'],
'mimeType': 'application/vnd.google-apps.spreadsheet',
}
res = drive.files().create(body=file_metadata).execute()
print(res)
出现错误:
<HttpError 403 when requesting https://www.googleapis.com/drive/v3/files?alt=json returned "Insufficient Permission: Request had insufficient authentication scopes.">
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
我发现没有Auth标头,我是匿名的,匿名使用的配额为零。如何设置标题或此错误的原因是其他原因?
我想要的只是从任何计算机在我的 gdrive 文件夹中创建一个带有 python 的电子表格,而无需单击某处来授予访问权限。
【问题讨论】:
标签: python google-drive-api google-sheets-api google-authentication google-console-developer