php - Google Calendar API v3 无法添加事件 php

标签 php google-api google-calendar-api

嘿,似乎无法使用此代码创建事件,

  <?php
require_once 'google-api-php-client/src/apiClient.php'
require_once 'google-api-php-client/src/contrib/apiCalendarService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("Cal");
$client->setClientId('');
$client->setClientSecret('');
//$client->setRedirectUri('http://localhost:8080/createEvent.php');
$client->setRedirectUri('http://localhost:8080/eventNew.php');
//http://localhost:8080/oauth2callback');
$client->setDeveloperKey('');
$cal = new apiCalendarService($client);

if (isset($_GET['logout'])) {
    unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}

$authUrl = $client->createAuthUrl();

if (!$client->getAccessToken()) {

$event = new Event();
$event->setSummary("test title");
$event->setLocation("test location");
$start = new EventDateTime();
$start->setDateTime('04-03-2012 09:25:00:000 -05:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('04-03-2012 10:25:00:000 -05:00');
$event->setEnd($end);
//$attendee1 = new EventAttendee();
//$attendee1->setEmail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="680d05090104280d05090104460b0705" rel="noreferrer noopener nofollow">[email protected]</a>');
//$attendees = array($attendee1);
//$event->attendees = $attendees;
$createdEvent = $cal->events->insert('primary', $event);

echo $createdEvent->getId();

$_SESSION['token'] = $client->getAccessToken();
}
?>

不断收到此错误消息:

Fatal error: Uncaught exception 'apiIOException' with message 'HTTP Error: (0) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' in C:\Program Files\EasyPHP-5.3.9\www\google-api-php-client\src\io\apiCurlIO.php:119 Stack trace: #0 C:\Program Files\EasyPHP-5.3.9\www\google-api-php-client\src\io\apiCurlIO.php(56): apiCurlIO->makeRequest(Object(apiHttpRequest)) #1 C:\Program Files\EasyPHP-5.3.9\www\google-api-php-client\src\io\apiREST.php(55): apiCurlIO->authenticatedRequest(Object(apiHttpRequest)) #2 C:\Program Files\EasyPHP-5.3.9\www\google-api-php-client\src\service\apiServiceResource.php(186): apiREST::execute(Object(apiServiceRequest)) #3 C:\Program Files\EasyPHP-5.3.9\www\google-api-php-client\src\contrib\apiCalendarService.php(493): apiServiceResource->__call('insert', Array) #4 C:\Program Files\EasyPHP-5.3.9\www\eventNew.php(47): EventsServiceResource->insert('primary', Object(Event)) #5 {main} thrown in C:\Program Files\EasyPHP-5.3.9\www\google-api-php-client\src\io\apiCurlIO.php on line 119

最佳答案

您的 Windows 上的 PHP 版本似乎未设置为验证对等 SSL 证书。

有一些信息在 this link其中描述了如何解决该问题。

基本上,您需要在 Windows 计算机上安装 CA bundle ,然后向代码中添加一行,告诉它在哪里查找 CA bundle 。

关于php - Google Calendar API v3 无法添加事件 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9515813/

相关文章:

php - 调用未定义的函数 curl_init() - 使用 WAMP

python - google api(表格)请求的身份验证范围不足

python - YouTube 数据 API v3 刷新 token 在发布状态设置为测试的应用程序上不断过期

c# - DotNetOpenAuth 与谷歌日历提要

PHP:在变量显示不需要的字符之前回显£符号

php - zend soap 服务器响应设置自定义 ns1 命名空间

rest - 谷歌日历 API : TimeZone not taken into account by google server?

ios - 使用 Google API 在 Objective C 中查询共享的 Google 日历

php - 如何使用 php 检查 smtp 服务器是否正常工作

ruby-on-rails - 使用 Signet 的 Google API,SSL 错误