以下の参考URLからpythonを用いてgoogleカレンダー情報を出力することができました。
https://developers.google.com/calendar/quickstart/python?hl=ja
次にgoogleカレンダーへの情報追加をするため、以下のURLを参考にしました。
すると
Google Calendar Insert API error “Insufficient Permission: Request had insufficient authentication scopes”
とエラーが表示されました。エラーを参考に[scopes]を
https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/calendar.events
など試してみましたが、エラーを対処できませんでした。
アドバイスよろしくお願いします。
python
1 2SCOPES = ['https://www.googleapis.com/auth/calendar',"https://www.googleapis.com/auth/calendar.events"] 3 4def main(): 5 6 creds = None 7 8 if os.path.exists('token.pickle'): 9 with open('token.pickle', 'rb') as token: 10 creds = pickle.load(token) 11 # If there are no (valid) credentials available, let the user log in. 12 if not creds or not creds.valid: 13 if creds and creds.expired and creds.refresh_token: 14 creds.refresh(Request()) 15 else: 16 flow = InstalledAppFlow.from_client_secrets_file( 17 '<jsonファイル>', SCOPES) 18 creds = flow.run_local_server() 19 # Save the credentials for the next run 20 with open('token.pickle', 'wb') as token: 21 pickle.dump(creds, token) 22 23 service = build('calendar', 'v3', credentials=creds) 24 25 event = { 26 'summary': 'Google I/O 2015', 27 'location': '800 Howard St., San Francisco, CA 94103', 28 'description': 'A chance to hear more about Google\'s developer products.', 29 'start': { 30 'dateTime': '2015-05-28T09:00:00-07:00', 31 'timeZone': 'America/Los_Angeles', 32 }, 33 'end': { 34 'dateTime': '2015-05-28T17:00:00-07:00', 35 'timeZone': 'America/Los_Angeles', 36 }, 37 'recurrence': [ 38 'RRULE:FREQ=DAILY;COUNT=2' 39 ], 40 'reminders': { 41 'useDefault': False, 42 'overrides': [ 43 {'method': 'email', 'minutes': 24 * 60}, 44 {'method': 'popup', 'minutes': 10}, 45 ], 46 }, 47 } 48 49 event = service.events().insert(calendarId='primary', body=event).execute() 50 print('Event created: %s' % (event.get('htmlLink'))) 51if __name__ == '__main__': 52 main()

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。