谷歌日历API v3访问未配置 [英] Google Calendar API v3 Access Not Configured

查看:203
本文介绍了谷歌日历API v3访问未配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让使用谷歌的API的V3从客户端的公共日历事件的列表。我进入日历ID进入 API浏览器和我得到一个阳性结果:

<$p$p><$c$c>https://www.googleapis.com/calendar/v3/calendars/rpsj44u6koirtq5hehkt21qs6k%40group.calendar.google.com/events?key={YOUR_API_KEY}`= GT; [事件列表在这里,预期]

要创建API密钥,我创建了谷歌开发者控制台中的一个项目,建立一个公共的API访问键( API和放大器;验证]>证书),并替换 { YOUR_API_KEY} 上面我的实际键。我确信,日历API被打开( API和放大器; AUTH>的API )。当我粘贴到浏览器的这个URL,我得到这个错误响应:

  {
 错误:{
  错误:
   {
    域:usageLimits
    原因:accessNotConfigured
    消息:访问未配置为您的项目未启用API,或者出现在你的API密钥配置每个IP或每个Referer的限制和要求不符合这些限制,请使用谷歌开发者控制台。更新你的配置。,
    extendedHelp:https://console.developers.google.com
   }
  ]
  code:403,
  消息:访问未配置为您的项目未启用API,或者出现在你的API密钥配置每个IP或每个Referer的限制和要求不符合这些限制,请使用谷歌开发者控制台。更新你的配置。
 }
}

我见过的所有答复说,你需要确保的谷歌日历API打开时,它肯定是(此外,这是默认开启)。缺少什么我在这里?


解决方案

使用谷歌的日历API沮丧我要几个小时,我想记录过于完整(超出此问题的范围)从几个来源答案为别人谁可能是有困难的。

首先,如果你像我一样,你得从你的日历设置公共地址:

有关我的公共日历,即XML链接是<一个href=\"https://www.google.com/calendar/feeds/dl9fj86o2ohe7o823s7jar920s%40group.calendar.google.com/public/basic\">this;但数据是混乱和,我想,再presented API的旧版本。逛了一下搜索后,我找到了第3版API正确的URL结构: <$c$c>https://www.googleapis.com/calendar/v3/calendars/dl9fj86o2ohe7o823s7jar920s%40group.calendar.google.com/events?key={API_KEY}.

但像这样的问题,我得到了一个错误。做到以下几点:

1。创建项目

做到这一点要到谷歌开发者控制台并点击创建项目。我被这个困惑,因为我的应用程序完全是前端的,我不认为我需要谷歌开发者项目。我错了;我需要一个项目,执行下一个步骤。

2。为您的项目创建一个API密钥

创建项目后,点击项目名称,并导航到 API和放大器; AUTH > 证书。在公共API访问,点击创建新密钥> {为key_type} > 创建;在我的情况 {为key_type} 浏览器键,因为我有一个完全的前端应用程序。跳过参照网址填写现在。这应该创建一个你,你插入到上面的网址(在那里说 {API_KEY}

API密钥

3。新增参照

如果你走到今天这一步,你应该看到错误OP在说什么。你得到这个错误的原因是,即使是公开日历,谷歌只允许指定的域的请求。所以,我可以发表我的日历的ID,甚至我的API密钥,另一个开发者将无法以编程方式访问我的日历没有我允许的。

要解决此问题,请单击编辑允许参照网址 -under API和放大器;验证]>证书 - 和添加(1)将发出请求的API和域名(2)如果你在本地开发的http://本地主机:{ PORT} / * 。请务必在末尾添加通配符。

4。从允许的域做一个HTTP请求

所有这些配置之后,你还是会得到一个错误,如果你只是将URL粘贴到浏览器中。这是因为要求有来自您刚刚允许的领域之一。只要从任何应用程序正在构建的请求。在我的例子中,JavaScript(jQuery的)看起来是这样的:

  $。阿贾克斯({
    输入:GET,
    网址:{} MY_URL,
    成功:功能(数据){
        //这里抛出一个调试器声明,
        //你应该能够检查数据。
    }
});

I'm trying to get a list of events from a client's public calendar using v3 of Google's API. I entered the Calendar ID into the API Explorer, and I'm getting a positive result:

https://www.googleapis.com/calendar/v3/calendars/rpsj44u6koirtq5hehkt21qs6k%40group.calendar.google.com/events?key={YOUR_API_KEY}`

=> [List of events here, as expected]

To create an API key, I created a project in the Google Developer Console, created a Public API access key (APIs & auth > Credentials), and replaced {YOUR_API_KEY} above with my actual key. I made sure that the Calendar API was turned on (APIs & auth > APIs). When I paste this URL in the browser, I get this error response:

{
 "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."
 }
}

All the responses I've seen say that you need to make sure the Google Calendar API is turned on, and it definitely is (also, it's turned on by default). What am I missing here?

解决方案

Using Google's Calendar API frustrated me for a couple of hours, and I want to document an overly complete (beyond the scope of this question) answer from a few sources for anyone else who may be having difficulty.

First, if you're like me, you got the public address from your calendar's settings:

For my public calendar, that XML link was this; but the data was messy and, I think, represented an older version of the API. After searching around a bit, I found the correct URL structure for the v3 API: https://www.googleapis.com/calendar/v3/calendars/dl9fj86o2ohe7o823s7jar920s%40group.calendar.google.com/events?key={API_KEY}.

But like this question, I was getting an error. Do the following:

1. Create a project

Do that by going to the Google Developer Console and clicking Create Project. I was confused by this because my application is entirely front-end, and I didn't think I needed Google Developer project. I was wrong; I needed a project to perform the next steps.

2. Create an API key for your project

After creating the project, click on the project name and navigate to APIs & auth > Credentials. Under "Public API access", click Create new key > {KEY_TYPE} > Create; in my case {KEY_TYPE} was Browser key since I have an entirely front-end application. Skip filling in referers for now. This should create you an API key that you insert into the URL above (where it says {API_KEY}.

3. Add referers

If you've made it this far, you should see the error OP was talking about. The reason you get this error is that even though the calendar is public, Google only allows requests from specified domains. So I could publish my calendar's ID and even my API key, and another developer would not be able to access my calendar programmatically without me allowing that.

To resolve this, click Edit allowed referers—under APIs & auth > Credentials—and add (1) the name of the domain that will be making the request to the API and (2) if you're developing locally http://localhost:{PORT}/*. Make sure you add the wildcard at the end.

4. Make an HTTP request from an allowed domain

After all of this configuration, you'll still get an error if you just paste the URL into your browser. This is because the request has to come from one of the domains you just allowed. Just make the request from whatever application you're building. In my case, the JavaScript (jQuery) looks like this:

$.ajax({
    type: 'GET',
    url: {MY_URL},
    success: function(data) {
        // Throw a debugger statement in here,
        // and you should be able to inspect your data.
    }
});

这篇关于谷歌日历API v3访问未配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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