首页 > 解决方案 > 通过 python Calendar API 添加与会者时超出日历使用限制

问题描述

我有一个使用谷歌日历 API 的服务器。但是今天我有一个问题。

 <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/9rmkucj5624ove5oe3dvlcchb8%40group.calendar.google.com/events/ilrgnanahon2scuq2hv9u6fcmg?alt=json returned "Calendar usage limits exceeded.">

json

{
  "error": {
    "code": 403,
    "message": "The request is missing a valid API key.",
    "errors": [
      {
        "message": "The request is missing a valid API key.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}

但是如果我使用 API 来创建事件、编辑事件,API 就起作用了!我添加与会者的功能

def update_event_employee_email(service, calendarId, eventId, employee_email,displayName):
    # First retrieve the event from the API.
    event = service.events().get(calendarId=calendarId, eventId=eventId).execute()
    #print(event)
    add_attendees = {
        "displayName": str(displayName),
        "email": str(employee_email)
        }
    try:
        current_attendees = event['attendees']
    except Exception as e:
        current_attendees=[]
    if current_attendees:
        attendees = event['attendees']
        attendees.append(add_attendees)
        body = {
            "attendees": attendees
        }
        print(attendees)
    else:
        body = {
              "attendees": [
                {
                    "displayName": str(displayName),
                    "email": str(employee_email)
                }
              ]
            }
    #print(event)
    try:
        event = service.events().patch(calendarId=calendarId, eventId=eventId, body=body).execute()
        print(event)
        status = 200
    except Exception as e:
        print(json.loads(e.content)['error']['code'])
        status = 400
    return status

我还检查了谷歌支持 避免日历使用限制

而且我认为我的 API 没有超出限制

向外部客人发送过多邀请

我更新:我的服务构建代码

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/calendar']


def service_build():
    """Shows basic usage of the Google Calendar API.
    Prints the start and name of the next 10 events on the user's calendar.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    print(os.path.exists('token.pickle'))
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('calendar', 'v3', credentials=creds)
    return service
    # Call the Calendar API

所以我想我的问题 例如:如果你有一个新的令牌,你可以发送任何一个 *. 50 场活动,有 100 位客人 - 每个活动有 2 位客人 *。25 场有 100 位宾客的活动 - 每个活动有 4 位宾客

每个限制

天数:36 位客人

周:252 位客人

月:~1080 位客人

所以我也想知道,如何购买更多的限制来增加更多的客人

标签: python-3.xgoogle-apigoogle-calendar-api

解决方案


您在避免日历使用限制下列出的配额是指谷歌日历的一般用法,如果您使用的是与 UI 相对的 API),则配额限制更严格。

Google 没有提供有关通过 Calendar API 使用添加与会者的最大配额的确切信息,可用信息是Google Calendar API 使用限制

Google Calendar API 有每天 1,000,000 次查询的礼貌限制。

要查看或更改项目的使用限制,或请求增加配额,请执行以下操作:

  1. 如果您的项目还没有结算帐号,请创建一个。
  2. 访问 API 控制台中 API 库的已启用 API 页面,然后从列表中选择一个 API。
  3. 要查看和更改与配额相关的设置,请选择配额。要查看使用情况统计信息,请选择使用情况。

换言之,您或许可以免费申请额外配额,但如果您已将配额增加到最大限额,您将无法获得更多配额 - 甚至付费。

现在到您的第二条错误消息:

The request is missing a valid API key

这听起来像是您的身份验证存在一些问题,并且 API 假定您正在尝试使用 API 密钥而不是有效的访问令牌进行身份验证。要丢弃代码实现问题,请测试您的Events: insertEvents:patch请求Try this API


推荐阅读