2
votes

I want to insert an event in one of my public calendars using the following code

var mykey = '273183670752-8419q1upedso5lc0hvtgfnbv32rd67um.apps.googleusercontent.com';
var calendarid = '7a97f6k4ok8v77jc2po6kkgcuo%40group.calendar.google.com';  
var meeting = 'Lunchafspraak 2 juli om 13:00';
var urlContent = 'https://www.googleapis.com/calendar/v3/calendars/' + calendarid + '/events/quickAdd?text=' + meeting + '&key=' + mykey;

$.ajax({
    type: 'POST',
    url: urlContent,
    dataType: 'json',
    success: function (response) {
        alert("Event toegevoegd");
    },
    error: function (response) {
        alert(response.error.errors);
        alert("Event niet toegevoegd");
    }
});

But it returns error 401 'login required'

What do I do wrong, and how do I solve this issue?

1

1 Answers

0
votes

Error 401 'login required' means that the access token you're using is either expired or invalid. As stated in this forum, you need to get the refresh token using the client ID and client secret to make authenticated and authorized API calls. Make sure you login with the right email when you are generating refresh token. In this case it would be your own user email address and not the service account email address. Service account email address is used for server to server applications.

Check these links:

Hope this helps!