Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically subscribe a user to a google calendar using javascript?

Hey i'm able to authenticate and authorize a user with the javascript API for google calendar. what i want to do next is subscribe that user to a public calendar. I was thinking i could just call the google.gdata.calendar.CalendarEntry constructor with the id of the calendar but that didn't work

var entry = google.gdata.calendar.CalendarEntry("idOfCalendar");

i also tried creating an instance of a entry id with google.gdata.atom.Id("idOfCalendar"); and adding that to the CalendarEntry constructor. Using the set methods didn't work either.

I use the InsertEntry method to add the entry but i get the following error

Error: Valid calendar id must be supplied for adding calendar to favorites list in allcalendars projection.

I can access the events of this calendar using google.gdata.calendar.CalendarEventQuery()

The google api for javascript doesn't give a lot of examples anyone know the answer to my problem or a good resource for working with the google calendar api? do you think i should be using php or jason instead?

** Edit I found an example of what I want in the Java Api link so i tried

function addSubscriptionToCalendar() {
    var feedUri = "http://www.google.com/calendar/feeds/default/allcalendars/full";
    var calendarEntry = new google.gdata.calendar.CalendarEntry();
    calendarEntry.setId("nhl_21_%54oronto+%4daple+%4ceafs#[email protected]");
    calendarService.insertEntry(feedUri, calendarEntry, function(){alert("calendar added")}, handleError);
}

but i got the same error

like image 333
Devin Crossman Avatar asked Apr 04 '11 05:04

Devin Crossman


People also ask

How do I automatically add events to Google Calendar?

In Google Calendar settings, go to “Events from Gmail,” and check the box next to "Show events automatically created by Gmail in my calendar."


1 Answers

You should be using owncalendars feed to modify/add calendar entry for the authenticated user not allcalendars.

like image 163
Sarath Avatar answered Nov 07 '22 06:11

Sarath