简体   繁体   English

调用POST(找不到404)Google Calendar API时出错

[英]Error calling POST (404 Not Found) Google Calendar API

I am trying to insert an event with Google Calendar API and PHP. 我正在尝试使用Google Calendar API和PHP插入事件。 Everytime I submit my form I get the below error message: 每次提交表单时,都会收到以下错误消息:

Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/{{MY-CALENDAR-ID-IS-HERE}}@group.calendar.google.com/events: (404) Not Found' in /Applications/MAMP/htdocs/dl-home/classes/google-api/io/Google_REST.php:66 Stack trace: #0 /Applications/MAMP/htdocs/dl-home/classes/google-api/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 /Applications/MAMP/htdocs/dl-home/classes/google-api/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 /Applications/MAMP/htdocs/dl-home/classes/google-api/contrib/Google_CalendarService.php(469): Google_ServiceResource->__call('insert', Array) #3 /Applications/MAMP/htdocs/dl-home/includes/add-memo.php(66): Google_EventsServiceResource->insert('56c1bc787c21b50...', Object(Google_Event)) #4 {main} thrown in /Applications/MAMP/htdocs/dl-home/classes/google-api/io/Google_REST.php on line 66

But I dont understand what the problem is, I have my Client ID, Calendar ID and Service Email in my script, I also made sure that the sharing permissions of my calendar are shared to my service email but still no luck. 但是我不明白问题出在哪里,我在脚本中有我的客户ID,日历ID和服务电子邮件,我还确保将日历的共享权限共享到服务电子邮件中,但是还是没有运气。 I did find similar issues here and here but those havent helped. 我确实在这里这里都发现了类似的问题,但是这些还没有帮助。 I also have review the php sample library prior to asking :) 在询问之前,我还查看了php示例库 :)

Here is my script: 这是我的脚本:

session_start();

//Call-in the google client library
require_once '../classes/google-api/Google_Client.php';
require_once '../classes/google-api/contrib/Google_CalendarService.php';

//Service and Client Acc Details
define('CLIENT_ID', '890699386256-mdpm4jr22iu6p6j4mi0bvlpgq602ri7g.apps.googleusercontent.com');
define('SERVICE_ACCOUNT_NAME', '890699386256-mdpm4jr22iu6p6j4mi0bvlpgq602ri7g@developer.gserviceaccount.com');
define('KEY_FILE', '../components/DL-Calendarapi-0a09ec997f6a.p12');

//New Session Open / Set Access Token
$client = new Google_Client();

$client->setApplicationName("Anything-here");
$client->setUseObjects(true);
if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

//Set Key Cred Details
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
  SERVICE_ACCOUNT_NAME,
  'https://www.google.com/calendar/feeds/56c1bc787c21b501a73c1e7e5776560f/private/full/',
  $key)
);

//Format the date to be 'friendly' with the google event input format
//This takes dates as dd/mm/yyyy and converts to yyyy-mm-dd
$df = DateTime::createFromFormat("d/m/Y", $_GET['dateFrom']);
$dt = DateTime::createFromFormat("d/m/Y", $_GET['dateTo']);
$datet = new DateTime($dt->format("Y-m-d"));
//Custom modify snippet to fix googles timezone error
$datet->modify('+1 day');
$client->setClientId(CLIENT_ID);
$cal = new Google_CalendarService($client);

//Create the event (Adding Details)
$event = new Google_Event();

//Event title set..
$event->setSummary($_GET['name']);
$event->setLocation('Anything-here-or-pass-variable');
$event->setDescription($_GET['comment']);

$start = new Google_EventDateTime();
$start->setDate($df->format("Y-m-d"));
$event->setStart($start);

$end = new Google_EventDateTime();
$end->setDate($datet->format("Y-m-d"));
$event->setEnd($end);

//Add the Event object to Calendar
$cal->events->insert('56c1bc787c21b501a73c1e7e5776560f@group.calendar.google.com', $event);
//Show success message
echo '<div id="message"><div id="message-body"><p>Event Created!</p></div></div>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM