前提・実現したいこと
ここに質問の内容を詳しく書いてください。
AWS lambdaでGoogleカレンダーとの連携をしたいです。
発生している問題・エラーメッセージ
Freebusy.queryで、予定の有無を取得しようとした際にこのようなエラーが発生します。
エラーメッセージ
"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
該当のソースコード
Javascript
1 2'use strict'; 3const {google} = require('googleapis'); 4const privatekey = require('./privatekey.json'); 5const calendar = google.calendar('v3'); 6 7exports.handler = (event, context, callback) => { 8 9 Promise.resolve() 10 .then(function(){ 11 return new Promise(function(resolve, reject){ 12 //JWT auth clientの設定 13 const jwtClient = new google.auth.JWT( 14 privatekey.client_email, 15 null, 16 privatekey.private_key, 17 ['https://www.googleapis.com/auth/calendar']); 18 //authenticate request 19 jwtClient.authorize(function (err, tokens) { 20 if (err) { 21 reject(err); 22 } else { 23 console.log("認証成功"); 24 resolve(jwtClient); 25 } 26 }); 27 }) 28 }) 29 //CalendarListの取得 30 .then(function(jwtClient){ 31 return new Promise(function(resolve,reject){ 32 33 calendar.calendarList.list({ 34 auth: jwtClient, 35 36 }, function (err, response) { 37 if (err) { 38 reject(err); 39 }else{ 40 const calendarId = response.data.items[0].id; 41 console.log(calendarId); 42 console.log('CalendarList取得'); 43 resolve([jwtClient,calendarId]); 44 } 45 }); 46 }) 47 }) 48 49 .then(function([jwtClient,calendarId]){ 50 return new Promise(function(resolve,reject){ 51 52 const params = { 53 "timeMin": "2019-03-11T10:00:00+09:00", 54 "timeMax": "2019-03-11T11:30:00+09:00", 55 "timeZone": 'Asia/Tokyo', 56 "items": [ 57 { 58 "id": calendarId 59 } 60 ]} 61 62 //予定が空いているか 63 calendar.freebusy.query(params, 64 function(err,response){ 65 if(err){ 66 reject(err); 67 }else{ 68 //カレンダーの予定達 69 console.log('data:',{response}); 70 const events = response.data.items; 71 //それぞれのPromiseでは、カレンダーの予定を返す 72 resolve(events); 73 } 74 }); 75 76 }) 77 }) 78 79 .then(function(result){ 80 callback(null, result); 81 }) 82 .catch(function(err){ 83 callback(err); 84 }); 85 86 };
試したこと
CalendarListは問題なく取得できますが、freebusyのところでのみエラーが返って来てしまいます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。