How to Define which Calendar to Connect to using Google Calendar API v3 Service

╄→尐↘猪︶ㄣ 提交于 2019-12-12 03:17:24

问题


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.

Here is what I've done so far:

  1. created a project in the Google Developer's Console
  2. turned on Calendar API
  3. installed PHP Client Library on my server from GitHub (yesterday - release 1.1.1)
  4. ensured JSON PHP Extension is installed on my server
  5. created OAuth 2.0 credentials
  6. created Public API Access key
  7. ensured my calendars are still publicly viewable (they have been since December 2010)

Here is my code snippet:

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');

Here is the error message I am getting:

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

Screen Shots:

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


回答1:


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

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

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.



来源:https://stackoverflow.com/questions/27111359/how-to-define-which-calendar-to-connect-to-using-google-calendar-api-v3-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!