Insert event to google calendar nodejs

add event to google calendar php
add event to google calendar javascript
android add event to google calendar programmatically
google calendar api nodejs
google calendar api c# create event
node.js calendar example
google calendar api example
add event to google calendar android studio

I'm reading through the docs on inserting events in to the google calendar api but not having any success. I was able to follow the quick start guide and pull a list of events from my google calendar but now I cant get the insert to work. I've kept the enviroment set up the same and just added the insert method but My error is There was an error contacting the Calendar service: Error: Insufficent Permission

const fs = require('fs');
const readline = require('readline');
const { google } = require('googleapis');
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
const TOKEN_PATH = 'credentials.json';

// Load client secrets from a local file.
try {
  const content = fs.readFileSync('client_secret.json');
  authorize(JSON.parse(content), insertEvents);
} catch (err) {
  return console.log('Error loading client secret file:', err);
}

/**
 * Create an OAuth2 client with the given credentials, and then execute the
 * given callback function.
 * @param {Object} credentials The authorization client credentials.
 * @param {function} callback The callback to call with the authorized client.
 * @return {function} if error in reading credentials.json asks for a new one.
 */
function authorize(credentials, callback) {
  const { client_secret, client_id, redirect_uris } = credentials.installed;
  let token = {};
  const oAuth2Client = new google.auth.OAuth2(
    client_id,
    client_secret,
    redirect_uris[0]
  );

  // Check if we have previously stored a token.
  try {
    token = fs.readFileSync(TOKEN_PATH);
  } catch (err) {
    return getAccessToken(oAuth2Client, callback);
  }
  oAuth2Client.setCredentials(JSON.parse(token));
  callback(oAuth2Client);
}
/**
 * Get and store new token after prompting for user authorization, and then
 * execute the given callback with the authorized OAuth2 client.
 * @param {google.auth.OAuth2} oAuth2Client The OAuth2 client to get token for.
 * @param {getEventsCallback} callback The callback for the authorized client.
 */
function getAccessToken(oAuth2Client, callback) {
  const authUrl = oAuth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: SCOPES
  });
  console.log('Authorize this app by visiting this url:', authUrl);
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  rl.question('Enter the code from that page here: ', code => {
    rl.close();
    oAuth2Client.getToken(code, (err, token) => {
      if (err) return callback(err);
      oAuth2Client.setCredentials(token);
      // Store the token to disk for later program executions
      try {
        fs.writeFileSync(TOKEN_PATH, JSON.stringify(token));
        console.log('Token stored to', TOKEN_PATH);
      } catch (err) {
        console.error(err);
      }
      callback(oAuth2Client);
    });
  });
}



function insertEvents(auth) {
  const calendar = google.calendar({ version: 'v3', 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'],
    attendees: [{ email: 'lpage@example.com' }, { email: 'sbrin@example.com' }],
    reminders: {
      useDefault: false,
      overrides: [
        { method: 'email', minutes: 24 * 60 },
        { method: 'popup', minutes: 10 }
      ]
    }
  };

  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);
    }
  );
}

I think that your scope is correct for using calendar.events.insert(). So how about this modification?

  1. I thought that the scope might be not reflected to the access token yet. So please remove credentials.json once, and authorize the scopes again. By this, it creates credentials.json again. And the access token and refresh token reflected the scope can be retrieved.
  2. In your script, event.htmlLink of console.log('Event created: %s', event.htmlLink) becomes undefined. So in the case of your script, please modify to console.log('Event created: %s', event.data.htmlLink).

If these are not useful for your situation, I'm sorry.

Node.js Quickstart | Calendar API, POST https://www.googleapis.com/calendar/v3/calendars/ calendarId /events For adding Google Drive file attachments use the same format as in  The (inclusive) start time of the event. For a recurring event, this is the start time of the first instance. #N#Optional Properties. anyoneCanAddSelf. Whether anyone can invite themselves to the event (currently works for Google+ events only). Optional. The default is False. attachments [].fileUrl. URL link to the attachment.

Please include SCOPE 'https://www.googleapis.com/auth/calendar.event'. This is required for working with calendar events.

Events: insert | Calendar API, js) Insert a New Google Calendar Event. Demonstrates how to insert a new Google Calendar event. Install Chilkat for Node.js and Electron using npm at. (Node.js) Insert a New Google Calendar Event. Demonstrates how to insert a new Google Calendar event. Install Chilkat for Node.js and Electron using npm at.

const fs = require('fs');
const readline = require('readline');
const { google } = require('googleapis');
const SCOPES = ['https://www.googleapis.com/auth/calendar'];
const TOKEN_PATH = 'credentials.json';

// Load client secrets from a local file.
try {
  const content = fs.readFileSync('client_secret.json');
  authorize(JSON.parse(content), insertEvents);
} catch (err) {
  return console.log('Error loading client secret file:', err);
}

/**
 * Create an OAuth2 client with the given credentials, and then execute the
 * given callback function.
 * @param {Object} credentials The authorization client credentials.
 * @param {function} callback The callback to call with the authorized client.
 * @return {function} if error in reading credentials.json asks for a new one.
 */
function authorize(credentials, callback) {
  const { client_secret, client_id, redirect_uris } = credentials.installed;
  let token = {};
  const oAuth2Client = new google.auth.OAuth2(
    client_id,
    client_secret,
    redirect_uris[0]
  );

  // Check if we have previously stored a token.
  try {
    token = fs.readFileSync(TOKEN_PATH);
  } catch (err) {
    return getAccessToken(oAuth2Client, callback);
  }
  oAuth2Client.setCredentials(JSON.parse(token));
  callback(oAuth2Client);
}
/**
 * Get and store new token after prompting for user authorization, and then
 * execute the given callback with the authorized OAuth2 client.
 * @param {google.auth.OAuth2} oAuth2Client The OAuth2 client to get token for.
 * @param {getEventsCallback} callback The callback for the authorized client.
 */
function getAccessToken(oAuth2Client, callback) {
  const authUrl = oAuth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: SCOPES
  });
  console.log('Authorize this app by visiting this url:', authUrl);
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  rl.question('Enter the code from that page here: ', code => {
    rl.close();
    oAuth2Client.getToken(code, (err, token) => {
      if (err) return callback(err);
      oAuth2Client.setCredentials(token);
      // Store the token to disk for later program executions
      try {
        fs.writeFileSync(TOKEN_PATH, JSON.stringify(token));
        console.log('Token stored to', TOKEN_PATH);
      } catch (err) {
        console.error(err);
      }
      callback(oAuth2Client);
    });
  });
}



function insertEvents(auth) {
  const calendar = google.calendar({ version: 'v3', auth });
  var event = {
    summary: 'Google I/O 2019',
    location: '800 Howard St.',
    description: "A chance to hear more.",
    start: {
      dateTime: '2019-11-28T09:00:00-07:00',
      timeZone: 'America/Los_Angeles'
    },
    end: {
      dateTime: '2019-11-28T10:00:00-07:00',
      timeZone: 'America/Los_Angeles'
    },
    recurrence: ['RRULE:FREQ=DAILY;COUNT=2'],
    attendees: [{ email: 'lpage@example.com' }, { email: 'sbrin@example.com' }],
    reminders: {
      useDefault: false,
      overrides: [
        { method: 'email', minutes: 24 * 60 },
        { method: 'popup', minutes: 10 }
      ]
    }
  };

  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.data.htmlLink);
    }
  );
}

Node.js Insert a New Google Calendar Event, json, and run npm install again. Import the library using const {google} = require('​googleapis'); , notice the {} around google. Node.js Quickstart. Step 1: Turn on the Google Calendar API. Click this button to create a new Cloud Platform project and automatically enable the Google Calendar API Step 2: Install the client library. Step 3: Set up the sample. Step 4: Run the sample. Troubleshooting.

Calendar API gives an error while inserting events using events , Refer to google api insert for the specifications of these fields. [code language=”​javascript”] var event = { 'summary': 'Google I/O 2015', 'location  The two parts of attaching a Google Drive file to an event are: Get the file alternateLink URL, title, and mimeType from the Drive API Files resource, typically with the files.get() method. Create

Create Google Calendar events using node.js, Now, let's look into adding events into the user's calendar. // Adding event into the calendarlet calendar = google.calendar({version: 'v3', auth}); calendar.events. Learn how to add a Google-like scheduler in an Node.js app, using a full-featured, open-source JavaScript event calendar dhtmlxScheduler.

Google calendar sync with NodeJS - Vishnu, gcal is a command line tool running in Node.js that allows event listing, insert or bulk insert through the Google Calendar API. Some use cases include  Creating an event on Google Calendar using NODEJS is not a big deal. There are lots of google APIs that can be used to create calendar event and share with someone. After creating events on google calendar attendees will get notify via email and also theey will get reminder about the events.

Comments
  • @monothorn Thank you. I'm glad your issue was solved.
  • after you run node . authorize this app by visiting the url and paste the code, event will be created
  • Adding an explanation to the post would be helpful.
  • Can anyone help me with deleting an event from google calendar node js @zmag
  • Need to send an instantaneous email to the attendees in the above code, any help is appreciated. ( Currently attendees are getting it one day before the event )