現在google chromeの拡張機能の開発をしており、その中でGoogle Calendar APIを利用し、カレンダーに入っている予定を取得したいと思っています。
こちらのチュートリアルを参考に、下記のようなコードでCalendar APIを叩くことまではできました。
JavaScript
1 2'use strict'; 3window.onload = function() { 4 document.querySelector('button').addEventListener('click', function() { 5 chrome.identity.getAuthToken({interactive: true}, function(token) { 6 let init = { 7 method: 'GET', 8 async: true, 9 headers: { 10 Authorization: 'Bearer ' + token, 11 'Content-Type': 'application/json' 12 }, 13 'contentType': 'json' 14 }; 15 fetch( 16 'https://www.googleapis.com/calendar/v3/calendars/primary/events', 17 init) 18 .then((response) => response.json()) 19 .then(function(data) { 20 console.log(data); 21 }); 22 }); 23 }); 24}; 25
ただこれだとカレンダーに入っている全ての予定をとってきてしまうため、開始日と終了日を指定してとってきたいと思っています。
このページを見るとどうやらtimeMaxとtimeMinというパラメーターを設定すると可能なようでしたので、URLにパラメーターをつけた下記のコードで実行したところ400エラーが返ってきてしまいました。
JavaScript
1 2'use strict'; 3window.onload = function() { 4 document.querySelector('button').addEventListener('click', function() { 5 chrome.identity.getAuthToken({interactive: true}, function(token) { 6 let init = { 7 method: 'GET', 8 async: true, 9 headers: { 10 Authorization: 'Bearer ' + token, 11 'Content-Type': 'application/json' 12 }, 13 'contentType': 'json' 14 }; 15 fetch( 16 'https://www.googleapis.com/calendar/v3/calendars/primary/events?timeMin=2018-06-01T09:59:59.000+09:00&timeMax=2018-06-01T23:59:59.000+09:00', 17 init) 18 .then((response) => response.json()) 19 .then(function(data) { 20 console.log(data); 21 }); 22 }); 23 }); 24}; 25
どなたか原因をご教授いただけないでしょうか。何卒よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/02 01:21