sea*_*ter 18 api calendar google-calendar-api google-api
我正在尝试使用Google API的v3从客户的公共日历中获取事件列表.我将日历ID输入API Explorer,我得到了一个积极的结果:
https://www.googleapis.com/calendar/v3/calendars/rpsj44u6koirtq5hehkt21qs6k%40group.calendar.google.com/events?key={YOUR_API_KEY}`
=> [List of events here, as expected]
Run Code Online (Sandbox Code Playgroud)
为了创建API密钥,我在Google Developer Console中创建了一个项目,创建了一个公共API访问密钥(API&auth> Credentials),并{YOUR_API_KEY}在上面替换为我的实际密钥.我确保打开了Calendar API(API和auth> API).当我在浏览器中粘贴此URL时,我收到此错误响应:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
}
}
Run Code Online (Sandbox Code Playgroud)
我见过的所有回复都说您需要确保Google Calendar API已开启,而且肯定是(默认情况下它已启用).我在这里错过了什么?
gwg*_*gwg 25
使用谷歌的日历API让我感到沮丧几个小时,我想记录一些过于完整(超出这个问题的范围)的答案来自几个来源的其他可能有困难的人.
首先,如果您像我一样,您可以从日历的设置中获取公共地址: 
对于我的公共日历,XML链接是这样的 ; 但数据很混乱,我认为,代表了旧版本的API.经过一番搜索后,我找到了v3 API的正确URL结构:https://www.googleapis.com/calendar/v3/calendars/dl9fj86o2ohe7o823s7jar920s%40group.calendar.google.com/events?key={API_KEY}.
但就像这个问题一样,我收到了一个错误.请执行下列操作:
1.创建一个项目
通过转到Google Developer Console并单击来完成此操作Create Project.我对此感到困惑,因为我的应用程序完全是前端的,我认为我不需要Google Developer项目.我错了; 我需要一个项目来执行后续步骤.
2.为项目创建API密钥
创建项目后,单击项目名称并导航到APIs & auth> Credentials.在"公共API访问",单击Create new key> {KEY_TYPE}> Create; 在我的情况下{KEY_TYPE},Browser key因为我有一个完全的前端应用程序.暂时填写参考资料.这应该会为您创建一个API密钥,您可以将其插入到上面的URL中(它所说的位置){API_KEY}.
3.添加引用者
如果你已经做到这一点,你应该看到OP正在谈论的错误.您收到此错误的原因是,即使日历是公开的,Google也只允许来自指定域的请求.所以我可以发布我的日历ID,甚至我的API密钥,而另一个开发人员无法在没有我允许的情况下以编程方式访问我的日历.
要解决此问题,请单击Edit allowed referers-under API&auth> Credentials - 并添加(1)将向API发出请求的域的名称,以及(2)如果您在本地进行开发http://localhost:{PORT}/*.确保在最后添加通配符.
4.从允许的域发出HTTP请求
完成所有这些配置后,如果只是将URL粘贴到浏览器中,仍会出现错误.这是因为请求必须来自您允许的其中一个域.只需从您正在构建的任何应用程序中提出请求.就我而言,JavaScript(jQuery)看起来像这样:
$.ajax({
type: 'GET',
url: {MY_URL},
success: function(data) {
// Throw a debugger statement in here,
// and you should be able to inspect your data.
}
});
Run Code Online (Sandbox Code Playgroud)
小智 5
您无需OAuth 2.0即可访问公共日历.
我遇到了与首先描述的sea_monster相同的问题,虽然我插入了一个公共API访问密钥并检查了API是否已打开,但我总是出错:
403,AccessNotConfigured,API未启用...
方案:
我必须转到Google Developer Console,选择我的项目,点击左侧的"API a Auth",然后点击"API"并选择Calendar API.虽然它已打开,但我不得不停用API,等待消息并再次打开API.现在我的代码工作,我没有必要改变它!
Ger*_*rdo -3
当您在 API Explorer 中测试调用时,您还必须激活“使用 OAuth 2.0 授权请求”选项,然后授权所请求的权限。在这种情况下,用户(即使是您自己)需要授权对信息的访问。
为了让应用程序访问用户的信息,需要使用 OAuth 2.0 完成身份验证过程。在这里您可以找到文档:https://developers.google.com/accounts/docs/OAuth2
您还可以使用 OAuth Playground ( https://developers.google.com/oauthplayground/ ) 进行 API 调用(如在 API 资源管理器中),但在本例中,要执行授权所需的步骤,在 API 资源管理器中执行这些步骤打开“使用 OAuth 2.0 授权请求”按钮时会自动完成。
希望这些信息有用。