创建事件时,Google Calendar API v3 服务帐户不发送通知

Vas*_*mis 5 google-calendar-api node.js oauth-2.0 service-accounts

我正在尝试使用 Google 服务帐户创建日历活动(在其自己的日历中)并邀请一些与会者。

当我使用服务帐户和 JWT 身份验证创建事件时,事件已成功创建,但受邀者未收到电子邮件通知 - 请参阅下面的代码。如果我使用客户帐户,则会发送电子邮件通知,但我不想诉诸于此。

难道我做错了什么?

var google = require('googleapis');
var SCOPES = ['https://www.googleapis.com/auth/calendar'];

var key = require("./API-Project-key.json");
var jwtClient = new google.auth.JWT(key.client_email, null, key.private_key, SCOPES, null);

jwtClient.authorize(function(err) {
    if (err) {
        console.log(err);
        return;
    }
    createEvent(jwtClient);

});

/**
 * @param {google.auth.OAuth2} auth An authorized OAuth2 client.
 */
function createEvent (auth) {
    var calendar = google.calendar('v3');


    var event = {
        'summary': 'Test Event',
        'location': 'London, UK',
        'description': 'This is a sample event',
        'start': {
            'dateTime': '2016-03-15T20:00:00',
            'timeZone': 'Europe/London',
        },
        'end': {
            'dateTime': '2016-03-15T21:00:00',
            'timeZone': 'Europe/London',
        },
        'attendees': [
            {'email': 'myemail@mydomain.com'}
        ]
    };

    calendar.events.insert({
        auth: auth,
        calendarId: 'primary',
        sendNotifications: true,
        resource: event
    }, function (err, event) {
        if (err) {
            return console.log(err, event);
        }
        return console.log(event);
    });
}
Run Code Online (Sandbox Code Playgroud)

dyl*_*ley 0

“sendNotifications”现已弃用。您需要将其更改为“sendUpdates”并传入参数“all”,如下所示:

calendar.events.insert({
    auth: auth,
    calendarId: 'primary',
    sendUpdates:'all',
    resource: event
}, function (err, event) {
    if (err) {
        return console.log(err, event);
    }
    return console.log(event);
});
Run Code Online (Sandbox Code Playgroud)

来自谷歌文档

Acceptable values are:

"all": Notifications are sent to all guests.
"externalOnly": Notifications are sent to non-Google Calendar guests only.
"none": No notifications are sent. This value should only be used for migration use cases (note that in most migration cases the import method should be used).
Run Code Online (Sandbox Code Playgroud)