简体   繁体   中英

undefined htmlLink Google Calendar Insert

Apparently i got a problem when i try to insert a new event on my GCalendar. Site return Event created: undefined, i made the connection and auth correctly, and can list my actual calendar events, but still unable to insert a new event

var test = {
            "summary":"TEST",
            "description":"TEST",
            "start":
            {
                "dateTime":"2017-01-01T12:00:00.000+01:00"
            },
            "end":
            {
                "dateTime":"2017-01-01T12:30:00.000+01:00"
            }
        };
        var request = gapi.client.calendar.events.insert({
            'calendarId': 'primary',
            'resource': test
        });

        request.execute(function(test) {
            appendPre('Event created: ' + test.htmlLink);
        });

Any solution?

You need to enclose the Events.insert codes inside a function which will be called after the authorization ( use the JS Quickstart ) is complete.

function loadCalendarApi() {
        gapi.client.load('calendar', 'v3', insertEvent);
}

//this is the function that will be called
function insertEvent() {

  var event = {
     'summary': 'Google I/O 2017',
     'location': '800 Howard St., San Francisco, CA 94103',
     'description': 'A chance to hear more about Google\'s developer products.',
     'start': {
       'dateTime': '2017-01-20T09:00:00-07:00',
       'timeZone': 'America/Los_Angeles'
  },
  .
  .

   request.execute(function(event) {
     appendPre('Event created: ' + event.htmlLink);
     console.log("Event added to Calendar");
   });

}

Full working code is here . Use your own CLIENT_ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM