Email notifications for events via the Google Calendar API

I use the calendar.events.insert API to add an event to my calendar through the PHP client. The event is correctly entered along with the corresponding values ​​set by the API. However, it cannot initiate an email invitation to participants. I looked around and found that the request should set the sendNotifications parameter to true . The same doesn't seem to help.

Here is a sample code:

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

If eventData and calendarData are appropriate objects.

Although my main problem is sending emails for the first time, I also tried (as seen above) to set a reminder (using overrides ). Although the popup works as expected, I also did not receive an email update in this case.

This makes me wonder if this might be a resolution problem - is there something I need to enable for my application (it would be clear to the user to find out if my application sends emails on their behalf)?

+6
source share
3 answers

@linaa is true. Just ran into this question.

In JS, it will look like this:

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

In the Google API documentation for inserting events, the "sendNotifications" parameter is actually a parameter. You may want to put it in the query parameters instead of the body.

In Meteor

Note. In my Meteor app, I made a manual request, and I'm still not familiar with JavaScript. I'm not sure how you will do this in plain JavaScript or using the calendar API, so I’ll just put the Meteor code in, I hope it helps, although it’s a little off topic.

 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 () {}); 
+1
source

To do this, you must set the value "remindOnRespondedEventsOnly" to "true".

which means whether to send event reminders only for events with the response status of users "Yes" and "Possible".

You can find this information here .

Hope this helps!

0
source

Source: https://habr.com/ru/post/1207184/


All Articles