Google日历错误权限不足

时间:2019-01-09 01:05:26

标签: python google-api google-calendar-api

我使用此代码测试Google日历api,当我使用calendarId='primary'时没有错误。

但是当我使用calendarId='uf0udovlhgel0u7a1ifs69o2u8@group.calendar.google.com'时。

我的pycharm控制台中的错误消息是:

  

gleapiclient.errors.HttpError:https://www.googleapis.com/calendar/v3/calendars/uf0udovlhgel0u7a1ifs69o2u8%40group.calendar.google.com/events?maxResults=10&singleEvents=true&orderBy=startTime&alt=json返回“ Inufficient “>

实际上,我有此日历ID,您可以在此图片中看到它: enter image description here

这是我的代码:

from __future__ import print_function
import datetime
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools

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

def main():
    """Shows basic usage of the Google Calendar API.
    Prints the start and name of the next 10 events on the user's calendar.
    """
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    store = file.Storage('token.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('./credentials.json', SCOPES)
        creds = tools.run_flow(flow, store)
    service = build('calendar', 'v3', http=creds.authorize(Http()))

    # Call the Calendar API
    now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
    print('Getting the upcoming 10 events')
    # events_result = service.events().list(calendarId='primary',
    #                                       maxResults=10, singleEvents=True,
    #                                       orderBy='startTime').execute()
    events_result = service.events().list(calendarId='uf0udovlhgel0u7a1ifs69o2u8@group.calendar.google.com',
                                        maxResults=10, singleEvents=True,
                                        orderBy='startTime').execute()
    events = events_result.get('items', [])
    if not events:
        print('No upcoming events found.')
    for event in events:
        start = event['start'].get('dateTime', event['start'].get('date'))
        print(start, event['summary'])


if __name__ == '__main__':
    main()

当我单击pycharm控制台中的链接时,错误是:

 {
 "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."
 }
}

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

我知道哪里出了问题,我的python文件位于文件夹A中,文件夹A中没有文件credentials.json

所以有错误。

这是一个非常愚蠢的错误。