温馨提示:本文翻译自stackoverflow.com,查看原文请点击:node.js - Insert event in google calendar using service account with Nodejs
google-calendar-api google-cloud-functions node.js service-accounts

node.js - 使用带有Node.js的服务帐户在Google日历中插入事件

发布于 2020-04-26 18:35:44

我无法使用带有服务帐户的Node.js插入事件。服务帐户电子邮件已添加到该帐户中,并具有对事件进行更改的权限。我的nodejs代码正在google云功能上运行这是我的代码:

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

};

当我使用read函数时,相同的代码可以正常工作。任何的想法 ?

查看更多

提问者
Lydia halls
被浏览
10
Jescanellas 2020-02-10 20:05

这是一个已知的错误

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.