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

查看:51
本文介绍了使用 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.

谢谢.

推荐答案

这是经过大量研究后的答案,我刚刚找到并使用了本指南来使用谷歌日历 apihttp://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 密钥都不起作用.然后我不得不像这里提到的那样使用没有任何引用的浏览器密钥:获取错误 403:未配置访问.请使用 Google Developers Console 为您的项目激活 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天全站免登陆