Insert event in google calendar using service account with Nodejs

偶尔善良 提交于 2020-08-09 08:13:18

问题


I can't insert an event using Nodejs with service account. The service account Email is already added into the account with the permission make changes to event My nodejs code is running on google cloud functions Here is my code:

const {
  google
} = require('googleapis');


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': '2020-02-10T13:00:00-05:00'
  },
  'end': {
    'dateTime': '2020-02-10T15:00:00-05:00'
  },
  'attendees': [{
    'email': 'Emailh@domain.com'
  }],
  'reminders': {
    'useDefault': false,
    'overrides': [{
        'method': 'email',
        'minutes': 24 * 60
      },
      {
        'method': 'popup',
        'minutes': 10
      },
    ],
  },
};

exports.helloWorld = (req, res) => {
  google.auth.getClient({
    scopes: 'https://www.googleapis.com/auth/calendar',
  }).then(auth => {
    const calendar = google.calendar({
      version: 'v3',
      auth
    });
    calendar.events.insert({
      auth: auth,
      calendarId: 'MyCalendarID',
      resources: 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);
    });
  })

};

the same code works fine when I use the function read. Any Idea ?


回答1:


This is a known bug

There is an issue when adding attendees to an event with a Service Account.

The current workaround is to impersonate a user using G Suite Domain-wide Delegation. If you do so, you should be able to create the events with attendees.

Another option is to remove the attendees from the Event creation request.



来源:https://stackoverflow.com/questions/60141138/insert-event-in-google-calendar-using-service-account-with-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!