Last active
June 5, 2020 02:52
-
-
Save cades/d194af6d2be7398cad75 to your computer and use it in GitHub Desktop.
讀取 google calendar api v3 / Events: list , 轉換成 FullCalendar 的格式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'), | |
request = require('request'), | |
parser = require('xml2json'), | |
calendar_id = '[email protected]', | |
api_key = 'AIzaSyBQal2rNhP5SRkU5hZytY7Yb8nYc5Q1nrc', | |
url = util.format('https://www.googleapis.com/calendar/v3/calendars/%s/events?key=%s', calendar_id, api_key); | |
request({url: url}, function(error, response, json){ | |
var data = JSON.parse(json), | |
transformed = data.items.map(function(event){ | |
return { | |
id: event.id, | |
title: event.summary || '忙碌', | |
start: event.start.dateTime || event.start.date, | |
end: event.end.dateTime || event.start.date, // because end.date may be the next day, cause a '2-all-day' event, we use start.date here. | |
allDay: !!event.start.date | |
}; | |
}); | |
console.log(JSON.stringify(transformed)); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment