admin管理员组文章数量:1316974
I'm trying to use Google Calendar API via JavaScript and keep getting the 401 error response while using the following code:
$.ajax({
dataType: "json",
url: "/<calendarID>?key=<my api key>",
success: function(result){
$('#result').html(result);
}
});
Is there something wrong in my usage of the API and how should I use the oAuth
? I already have a clientID
and secretID
from the Google console but don't know how to use those.
Thanks.
I'm trying to use Google Calendar API via JavaScript and keep getting the 401 error response while using the following code:
$.ajax({
dataType: "json",
url: "https://www.googleapis./calendar/v3/users/me/calendarList/<calendarID>?key=<my api key>",
success: function(result){
$('#result').html(result);
}
});
Is there something wrong in my usage of the API and how should I use the oAuth
? I already have a clientID
and secretID
from the Google console but don't know how to use those.
Thanks.
Share Improve this question edited Nov 15, 2017 at 22:02 Axel 3,32311 gold badges37 silver badges60 bronze badges asked Aug 28, 2014 at 22:04 Joe SaadJoe Saad 1,9503 gold badges22 silver badges33 bronze badges 4- I don't think you can simply call that API like this because Google wants the user to manually authorize the access. Paste your url into browser and see what happens. – Allen King Commented Aug 28, 2014 at 22:13
- I know I may be missing something with authentication. Pasting the url, i get the following: { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" } } – Joe Saad Commented Aug 28, 2014 at 22:18
- The way this API works is that first you use a different url that is provided by Google API and pass in your api key and return url. That url then first redirects to login page, then authorization page. In the return url you get a token that you can use in REST api to retrieve data. Check Google documentation. – Allen King Commented Aug 29, 2014 at 2:15
- I'm using the url that is being generated from this tool provided by google, developers.google./google-apps/calendar/v3/reference/… there, you enter your ID and it gets you the URL.I checked google documentation and have been in it for few days now, do you remend a certain page to read again? Thanks! – Joe Saad Commented Aug 29, 2014 at 15:22
2 Answers
Reset to default 4Here's the answer after quite a bit of research, I just found and used this guide for using google calendar api http://googleappsdeveloper.blogspot./2011/12/using-new-js-library-to-unlock-power-of.html
Then I still was confused since the api key wasn't working every I tried regenerating it a couple of times. Then I had to use the browser key without any referrers just as mentioned here: Getting Error 403: Access Not Configured. Please use Google Developers Console to activate the API for your project
and finally I got everything working.
Here's also a main article for understanding the OAuth2 https://developers.google./accounts/docs/OAuth2
In order to use Google Calendar API, you not only need the client ID and client secret but in most cases (other than accessing public calendars) you also need to have your user authenticated. One way to achieve that is using Oauth2.
I remend using the client library that you can download here: https://developers.google./google-apps/calendar/downloads
Also there is an example on how to use the library here: https://developers.google./api-client-library/javascript/samples/samples
本文标签: javascriptUsing Google Calendar API returns 401 (unauthorized)Stack Overflow
版权声明:本文标题:javascript - Using Google Calendar API returns 401 (unauthorized) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742020714a2414600.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论