我在 Google Drive API 请求中遇到错误:“抱歉,您已超出共享配额。”,但请求很少 五个小时平均有235个请求,上次有30个错误(截图1)。所有最后的请求都会出错。 但控制台上的所有限制均已满(屏幕截图 2)。 我做错了什么?
要求是:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys, json, base64, time
import httplib2
import apiclient.discovery
from oauth2client.service_account import ServiceAccountCredentials
input_data = json.loads(base64.b64decode(sys.argv[1]))
user_mail = input_data['user_mail']
admin_mail = input_data['admin_mail']
donor_spreadsheet_id = input_data['donor_spreadsheet_id']
#donor_spreadsheet_id = '*****' #hided
CREDENTIALS_FILE = '*****.json' #hided
scope = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(CREDENTIALS_FILE, scope)
httpAuth = credentials.authorize(httplib2.Http())
driveService = apiclient.discovery.build('drive', 'v3', http=httpAuth)
try:
new_spreadsheet = driveService.files().copy(fileId=donor_spreadsheet_id).execute()
except Exception as e:
print('Copy error: ', json.loads(e.content)['error']['errors'][0]['message'])
try:
shareRes = driveService.permissions().create(
fileId = new_spreadsheet['id'],
body = {'type': 'user', 'role': 'writer', 'emailAddress': user_mail},
fields = 'id'
).execute()
except Exception as e:
print('Adding user mail error: ', json.loads(e.content)['error']['errors'][0]['message'])
new_url = 'https://docs.google.com/spreadsheets/d/' + new_spreadsheet['id'] + '/'
print(new_url)
抱歉,您已超出共享配额。
这就是说,Google Drive 附加了一些配额。首先,您所达到的配额与 API 本身无关,因此您不会在 Google Cloud Console 中看到它,如图所示。
Google Cloud Console 仅显示 API 相关配额。这些配额可以防止我们在每次使用或每个项目中淹没 API。
您所达到的配额是一般 Google 云端硬盘配额。
调试它需要一些时间,据我所知谷歌还没有实际记录硬数据。这可能是因为如果他们更改它们,他们将不得不更新文档。
如何调试。
获取错误,然后尝试通过网络应用程序与其他人分享。如果它不允许您,那么您可能已经达到了文件可以共享的最大用户数。
如果您可以实现指数退避并再次尝试通过 API 插入它。我似乎记得 4 小时内可以共享文件的用户数量有限制。自从我与遇到此问题的客户合作以来至少已有六年了,因此该数字可能已发生变化。
如果是洪水配额,那么您可能需要等到美国西部午夜(太平洋时间)才能重置。
我一直在寻找,但找不到任何给出实际数字的文档。
我在问题论坛上发布了一个问题抱歉,您已经超出了共享配额。 索取文件。