Using google calendar API returns 401 (unauthorized)

I am trying to use the Google Calendar API via JavaScript and keep getting a 401 error response when using the following code:

$.ajax({ 
   dataType: "json", 
   url: "https://www.googleapis.com/calendar/v3/users/me/calendarList/<calendarID>?key=<my api key>", 
   success: function(result){ 
   $('#result').html(result); 
   } 
});

      

Is there something wrong with my API usage and how should I use it oAuth

? I already have clientID

and secretID

from google console, but I don't know how to use them.

Thank.

+3


source to share


2 answers


Here is the answer after quite a bit of research, I just found and used this guide to use the google calendar api http://googleappsdeveloper.blogspot.com/2011/12/using-new-js-library-to-unlock-power-of. html

Then I was still confused as the api key didn't work every time I tried to regenerate it a couple of times. Then I had to use a browser key without links as mentioned here: Getting error 403: Access not configured. Use the Google Developers Console to activate the API for your project



and finally everything works for me.

Here's also a main article for understanding OAuth2 https://developers.google.com/accounts/docs/OAuth2

+3


source


To use the Google Calendar API, you not only need a Client ID and Client Secret, but in most cases (other than accessing public calendars) you also need your user to be authenticated. One way to achieve this is to use Oauth2.

I recommend using the client library that you can download here: https://developers.google.com/google-apps/calendar/downloads



There is also an example on how to use the library here: https://developers.google.com/api-client-library/javascript/samples/samples

+2


source







All Articles