質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

1939閲覧

Google Calendar Insert API error “Insufficient Permission: Request had insufficien

akihir

総合スコア39

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/07/10 14:22

以下の参考URLからpythonを用いてgoogleカレンダー情報を出力することができました。

https://developers.google.com/calendar/quickstart/python?hl=ja

次にgoogleカレンダーへの情報追加をするため、以下のURLを参考にしました。

https://developers.google.com/calendar/v3/reference/events/insert?hl=ja&apix_params=%7B%22calendarId%22%3A%22asd%22%2C%22resource%22%3A%7B%22end%22%3A%7B%7D%2C%22start%22%3A%7B%7D%7D%7D#try-it

すると

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()

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

見たところ、スクリプト自体に問題はないと思われます。イベント作成はhttps://www.googleapis.com/auth/calendar.eventsのスコープで問題ありません。そこで、ご確認頂きたいことがあります。

スコープを変更した際は、一度token.pickleファイルを削除し、再度認証を行う必要がありますが、これについては如何でしょうか。

もしもこれを行っていないようですと、一度、token.pickleファイルを削除してから再度スクリプトを実行して認証を行い、使用するスコープを承認してください。これによりコードが取得され、これを使用して変更したスコープが反映されたアクセストークンを取得することができます。

投稿2019/07/19 06:20

kisojin

総合スコア899

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問