簡體   English   中英

通過 Google Calendar API 發送事件的電子郵件通知

[英]Sending email notifications for Events via Google Calendar API

我正在使用calendar.events.insert API 通過 PHP 客戶端向我的日歷添加一個事件。 事件與 API 設置的適當值一起被正確插入。 然而,同樣無法觸發對與會者的電子郵件邀請。 我環顧四周,發現請求需要將參數sendNotifications設置為true 同樣的似乎也無濟於事。

這是一個示例代碼:

var request = gapi.client.calendar.events.insert({
        "calendarId" : calendarData.id,
        "sendNotifications": true,
        "end": {
          "dateTime": eventData.endTime
        },
        "start": {
          "dateTime": eventData.startTime
        },
        "summary": eventData.eventName, 
        "attendees": jQuery.map(eventData.attendees, function(a) {
          return {'email' : a};
        }),
        "reminders": {
          "useDefault": false,
          "overrides": [
            {
              "method": "email",
              "minutes": 15
            },
            {
              "method": "popup",
              "minutes": 15
            }
          ]
       }
      });

其中 eventData 和 calendarData 是合適的對象。

雖然我的主要問題是第一次發送電子郵件邀請,但我也嘗試(如上所示)設置提醒(使用overrides )。 雖然彈出窗口按預期工作,但在這種情況下我也沒有收到電子郵件更新。

這讓我想知道這是否可能是一個權限問題——我可能需要為我的應用程序啟用一些東西(用戶可以理解地需要知道我的應用程序是否代表他們發送電子郵件)?

用於插入事件Google API 文檔中,“sendNotifications”選項實際上是一個參數。 您可能希望將它放在請求參數而不是正文中。

在流星

注意:在我的 Meteor 應用程序中,我確實手動完成了請求,而且我還是 JavaScript 的新手。 我不確定你會如何用純 JavaScript 或日歷 API 來做到這一點,所以我只放了 Meteor 代碼,希望它有所幫助,盡管它有點偏離主題。

var reqUrl = "https://www.googleapis.com/calendar/v3/calendars/primary/events";
var payload = {
  'headers' : {
    'Authorization': "Bearer " + token,
    'Content-Type': 'application/json'
  },
  'params': {
    'sendNotifications': true
  },
  'data': {
    "summary": summary,
    "location": "",
    "start": {
      "dateTime": start
    },
    "end": {
      "dateTime": end
    },
    "attendees": [
      {
        "email": "*********@gmail.com"
      }
    ]
  }
};
Meteor.http.post(reqUrl, reqParams, function () {});

@linaa 是正確的。 剛剛自己遇到了這個問題。

在 JS 中,這看起來像:

var request = gapi.client.calendar.events.insert(
    sendNotifications: true,
    {
              // request body goes here
    }
);

為此,您應該將“remindOnRespondedEventsOnly”值設置為“true”。

這意味着,是否應該僅針對用戶響應狀態為“是”和“可能”的事件發送事件提醒。

您可以在此處找到此信息。

希望有幫助!

event = service.events().insert(calendarId='primary', body=event, sendUpdates='all').execute()

這會起作用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM