question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calendar API gives an error while inserting events using events.insert

See original GitHub issue

Hi, I used the code sample in Quickstart and tried inserting an event using the example on - https://developers.google.com/calendar/v3/reference/events/insert#examples

I checked the resources available over the web and none of them seem to be working for me (downgrading googleapis package to version 24.0.0 or using different ways of writing the insert event). This is the code of the addEvents function currently -

function addEvents(auth){

var event = {
  "summary": "Google I/O 2015",
  "location": "800 Howard St., San Francisco, CA 94103",
  "description": "A chance to hear more about Google\'s developer products.",
  "start": {
    "dateTime": "2015-05-28T09:00:00-07:00",
    "timeZone": "America/Los_Angeles",
  },
  "end": {
    "dateTime": "2015-05-28T17:00:00-07:00",
    "timeZone": "America/Los_Angeles",
  },
  "recurrence": [
    "RRULE:FREQ=DAILY;COUNT=2"
  ],
  "reminders": {
    "useDefault": false,
    "overrides": [
      {"method": "email", "minutes": 24 * 60},
      {"method": "popup", "minutes": 10},
    ],
  },
};

//console.log(event)

  var calendar = google.calendar("v3");

  calendar.events.insert({
  auth: auth,
  calendarId: "primary",
  resource: event,
}, function(err, event) {
  if (err) {
    console.log("There was an error contacting the Calendar service: " + err);
    return;
  }
  console.log("Event created: %s", event.htmlLink);
});

}

It is on the same lines as the listEvents function -

function listEvents(auth) {
var calendar = google.calendar('v3');
calendar.events.list({
    auth: auth,
    calendarId: 'primary',
    timeMin: (new Date()).toISOString(),
    maxResults: 10,
    singleEvents: true,
    orderBy: 'startTime'
    },
    function(err, response) {
    if (err) {
      console.log('The API returned an error: ' + err);
      return;
    }
    var events = response.items;
    if (events.length == 0) {
      console.log('No upcoming events found.');
    }
    else {
      console.log('Upcoming 10 events:');
      for (var i = 0; i < events.length; i++) {
        var event = events[i];
        var start = event.start.dateTime || event.start.date;
        console.log('%s - %s', start, event.summary);
    }
    }
  });
}

Can anyone please help me with this?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
JustinBeckwithcommented, Mar 10, 2018

Greetings! Sadly the docs on developers.google.com are out of date; we are working to get them fixed. In the interim - here are a few changes you need to make:

  1. Make sure you didn’t npm install google-auth-library. If you did, delete it from your package.json, and run npm install again.

  2. Import the library using const {google} = require('googleapis');, notice the {} around google.

  3. In your callback, instead of looking for response.items, use response.data.items. This will be required in any of the callbacks coming from the API.

I am guessing that after doing these things, you’ll be back on rails 😃 Let me know if you run into any problems!

0reactions
Sai-kiran-Yalagandhalacommented, Feb 24, 2021

(for some reason my code is not displayed correctly, let me know if you need entire quickstart.js file content)

if you could share us the snippet it will be very helpful

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calendar API gives an error while inserting events using ...
Calendar API gives an error while inserting events using events.insert: There was an error contacting the Calendar service: Error: Missing end ...
Read more >
Handle API errors | Google Calendar
The rest of this page provides a reference of Calendar errors, with some guidance on ... If you're using Events: insert, Events: import,...
Read more >
Time Range Error - Google Groups
I am creating calendar events using the Calendar API v3 (.NET). I can use the events QuickAdd method but receive an errror when...
Read more >
How to Use the Google Calendar API With JavaScript - Fusebit
If you don't have any errors in the code, Google Calendar will successfully add the event. List Events Using Google Calendar API. Now...
Read more >
error 403: “Calendar usage limits exceeded” when adding ...
When trying to use the Calendar API to 'insert' new events with external attendees, I hit some kind of quota limit after about...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found