使用Google Calendar API返回401(未经授权) [英] Using Google Calendar API returns 401 (unauthorized)

查看:250
本文介绍了使用Google Calendar API返回401(未经授权)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过JavaScript使用Google Calendar API,并在使用以下代码时不断收到401错误响应:

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.com/calendar/v3/users/me/calendarList/<calendarID>?key=<my api key>", 
   success: function(result){ 
   $('#result').html(result); 
   } 
});

我在使用API​​时是否有问题,应该如何使用oAuth?我已经从Google控制台中获得了clientIDsecretID,但是不知道如何使用它们.

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.

谢谢.

推荐答案

这是经过大量研究的答案,我刚刚找到并使用了本指南来使用Google Calendar API http://googleappsdeveloper. blogspot.com/2011/12/using-new-js-library-to-unlock-power-of.html

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

然后我仍然感到困惑,因为每次尝试重新生成api密钥都不起作用.然后,我不得不使用没有任何引荐来源网址的浏览器密钥,如此处所述:

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

最后我一切正常.

这也是了解OAuth2的主要文章 https://developers.google.com/accounts/docs/OAuth2

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

这篇关于使用Google Calendar API返回401(未经授权)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆