indraja boya
indraja boya

Reputation: 19

Inserting events in to google calendar using gives an error 404 "NOT FOUND"

I am creating a Node JS (Express) web app that will display a user's Google Calendar events, once they have logged in and insert events events into google calendar from my database.

I am trying to insert events via the Google Calendar API with a service account

Code I used :

var   googleapis = require("googleapis"),
    googleCal = googleapis.calendar("v3"),
    serviceEmail = "*****@*******gserviceaccount.com",
    serviceKeyFile = "./key.p12";

var authClient = new googleapis.auth.JWT(
        serviceEmail,
        serviceKeyFile,
        null,
        ["https://www.googleapis.com/auth/calendar"]
    );

authClient.authorize(function (err, tokens) {
  console.log("tokens"+JSON.stringify(tokens));
    if (err) {
        console.log(err);
    } else {
        googleCal.events.list({
            auth: authClient,
            calendarId: "*********@gmail.com",
            fields: {
                items: ["end","start","summary"]
            }
        }, function (err, CL) {
            if (err) {
                console.log(err);
            } else {
                console.log("calendar"+CL);
            }
        });
    }
})
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': '2017-07-28T09:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'end': {
    'dateTime': '2017-07-28T17:00:00-07:00',
    'timeZone': 'America/Los_Angeles',
  },
  'recurrence': [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  'attendees': [
    {'email': '[email protected]'},
    {'email': '[email protected]'},
  ],
  'reminders': {
    'useDefault': false,
    'overrides': [
      {'method': 'email', 'minutes': 24 * 60},
      {'method': 'popup', 'minutes': 10},
    ],
  },
};
googleCal.events.insert({
    auth: authClient,
    calendarId:'primary',
     resource: event,
}, function (err, events) {
    if (err) {
        console.log("there is an error"+err);
    } else {
        console.log(events);
        console.log("events are created successfully");
    }
})

My problem is while executing it is displaying an error like

{ Error: Not Found at Request._callback (D:\studentportal\node_modules\google-auth-library\lib\transporters.js:85:15) at Request.self.callback (D:\studentportal\node_modules\request\request.js:186:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (D:\studentportal\node_modules\request\request.js:1081:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage. (D:\studentportal\node_modules\request\request.js:1001:12) at IncomingMessage.g (events.js:291:16) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9) code: 404, errors: [ { domain: 'global', reason: 'notFound', message: 'Not Found' } ] }

What is the solution for this?

Upvotes: 0

Views: 915

Answers (1)

Danee
Danee

Reputation: 322

Try to check this and hopefully it helps you Handle API Error: 404

404: Not Found

The specified resource was not found. This can happen in several cases. Here are some examples:

when the requested resource (with the provided ID) has never existed when accessing a calendar that the user can not access

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

Upvotes: 0

Related Questions