I want to insert an event in one of my public calendars using the following code, But it returns error 401 login required
I am getting Request is missing required authentication credential. Expected OAuth 2 access token error while insert events. Where I am doing wrong ?
Here is my code
var mykey = "MY API KEY";
var calendarid = "MY CALENDAR ID LIKE [email protected]";
var event = {
summary: "Google I/O 2015",
location: "800 Howard St., San Francisco, CA 94103",
description: "Heyyyyyy",
start: {
dateTime: "2021-02-16T09:00:00-07:00",
timeZone: "America/Los_Angeles",
},
end: {
dateTime: "2021-02-17T17:00:00-07:00",
timeZone: "America/Los_Angeles",
},
recurrence: ["RRULE:FREQ=DAILY;COUNT=2"],
attendees: [
{ email: "[email protected]" },
{ email: "[email protected]" },
],
reminders: {
useDefault: false,
overrides: [
{ method: "email", minutes: 24 * 60 },
{ method: "popup", minutes: 10 },
],
},
};
$.ajax({
type: "POST",
url: encodeURI(
"https://www.googleapis.com/calendar/v3/calendars/" +
calendarid +
"/events/?key=" +
mykey
),
dataType: "json",
data: event,
success: function (response) {
//do whatever you want with each
},
error: function (response) {
//tell that an error has occurred
},
});```
Get API is working fine, but I am getting above error with post API.
I do not know whY I am getting this error. Can anyone help me ? What is the issue ?
