Fullcalendar jQuery - Possible to retrieve colour from google calendar?
I know it is possible to set the colour for events based on a source such as a google calendar, but I was wondering if there is any way to retrieve the colour automatically as it is set on the google calendar开发者_开发问答 itself?
Looking through the gcal.js, there doesn't seem to be anything pushed regarding the colour, but in google's json api (json-c however), there is a reference to the colour.
http://code.google.com/apis/calendar/data/2.0/developers_guide_protocol.html#RetrievingAllCalendars
I suppose it is a matter of a feature request to Fullcalendar but I'm wondering if I am missing something already in there?
Thank you!
The color of the calendar is not in the XML,ICAL Feed. It is only shown in the list of calendars available from a user. It lists the calendars and uses the: GCal namespace element reference
Google Calendar provides several extension elements for use in a metafeed (the feed that lists the user's calendars). These elements are in the gCal namespace, not the Google Data namespace, because they're specific to Calendar
So unfortunately, gcal.js does not support getting the list and you will not get the color unless you use another plugin to do so.
In that case it would have been as easy as this. In the gcal.js where the push it - I think you can add something in the line of
color: entry['gCal$color']['value'],
Google Source feed contains this value: (Calendar list - not calendar)
<gCal:color value='#2952A3' />
Previously answered a gcal/fullcalendar question at fullcalendar jQuery - Possible to retrieve description from Google Calendar events?. You will need to modify the source of gcal.js
. You might want to just hang the Google Calendar object off the event (so you can access the color and everything else):
events.push({
id: entry['gCal$uid']['value'],
title: entry['title']['$t'],
url: url,
start: start,
end: end,
allDay: allDay,
location: entry['gd$where'][0]['valueString'],
description: entry['content']['$t'],
entry: entry
});
I did that https://developers.google.com/google-apps/calendar/v3/reference/colors/get#examples But in JavaScipt. It's works for me.
function getColors() {
gapi
.client
.load('calendar', 'v3')
.then(function () {
request = gapi.client.calendar.colors.get({
'calendarId': calendarId -> "Your CalendarID"
});
request.then(function (resp) {
if (resp.result.error) {
reportError('Google Calendar Colors: ' + data.error.message, data.error.errors);
} else if (resp) {
console.log('--- resp ---');
console.log(resp.result);
}
}, function (reason) {
console.log('Error: ' + reason.result.error.message);
});
});
}
精彩评论