如何使用Google Calendar API v3服务定义要连接的日历 [英] How to Define which Calendar to Connect to using Google Calendar API v3 Service

查看:65
本文介绍了如何使用Google Calendar API v3服务定义要连接的日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以一种格式良好的方式在我的网页上列出某个公共日历中的所有事件,而没有让一般/公共访问者以任何方式登录或验证我的网站.自2010年12月以来,我一直使用v1和Zend Framework进行此操作. Google在2014年11月17日弃用了v1和v2,现在我的网页已损坏.

I am trying to list all the events in a certain public calendar in a nicely formatted manner on my web page without having a general/public visitor to my web site login or authenticate in any way. I have been doing this since December 2010 using v1 and the Zend Framework. On November 17, 2014 Google deprecated v1 and v2 and now my web page is broken.

这是我到目前为止所做的:

  1. 在Google开发者控制台中创建了一个项目
  2. 打开了Calendar API
  3. 从GitHub(昨天-版本1.1.1)在我的服务器上安装了PHP客户端库
  4. 确保在我的服务器上安装了JSON PHP扩展
  5. 创建了OAuth 2.0凭据
  6. 创建的公共API访问密钥
  7. 确保我的日历仍然可以公开查看(自2010年12月以来)

这是我的代码段:

require_once 'autoload.php'; // 2014-11-24 part of /usr/local/lib/php/google-api-php-client
$client = new Google_Client();
$client->setApplicationName("One_of_my_Calendars");
$client->setDeveloperKey("MY-PUBLIC-API-ACCESS-KEY"); // 2014-11-24 my Public API Access Key
$service = new Google_Service_Calendar($client);
$results = $service->events->listEvents('primary');

这是我收到的错误消息:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/calendar/v3/calendars/primary/events?key=MY-PUBLIC-API-ACCESS-KEY: (403) 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.' in /usr/local/lib/php/google-api-php-client/src/Google/Http/REST.php:76 Stack trace: #0 /usr/local/lib/php/google-api-php-client/src/Google/Http/REST.php(41): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request)) #1 /usr/local/lib/php/google-api-php-client/src/Google/Client.php(548): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) #2 /usr/local/lib/php/google-api-php-client/src/Google/Service/Resource.php(190): Google_Client->execute(Object(Google_Http_Request)) #3 /usr/local/lib/php/google-api-php-client/src/Google/Servi in /usr/local/lib/php/google-api-php-client/src/Google/Http/REST.php on line 76

屏幕截图:

https://drive.google.com/file/d/0Bytqhoir_Tt5ODRaNzRvS2FZRWs/view?usp = sharing https://drive.google.com/file/d/0Bytqhoir_Tt5MzlqLWF2Q3M2bUk/view ?usp =分享

推荐答案

假设您正在访问公共日历(因此不需要Oauth2),仍然存在两个问题:

Assuming you are accessing public calendars (so no need for Oauth2), there are still two issues:

第1个问题,您需要在开发者控制台中启用了Calendar API的项目中具有有效的API密钥.

Issue no.1 you need to have a working API key from a project which has Calendar API enabled in the developer console.

第2个问题是您未通过身份验证就使用了关键字主要".将其替换为您要访问的日历的电子邮件地址.

Issue no.2 is your usage of the keyword "primary" without being authenticated. Replace it with the email address of the calendar that you want to access.

这篇关于如何使用Google Calendar API v3服务定义要连接的日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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