使用带有Node.js的服务帐户在Google日历中插入事件 [英] Insert event in google calendar using service account with Nodejs

查看:87
本文介绍了使用带有Node.js的服务帐户在Google日历中插入事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

};

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

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

推荐答案

这是一个已知的错误

在使用服务帐户向活动添加参与者时,会出现问题.

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

当前解决方法是使用全域G Suite 假冒用户委托.如果这样做,您应该可以与参加者一起创建活动.

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.

这篇关于使用带有Node.js的服务帐户在Google日历中插入事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆