Google Calendar API v3 无法添加事件 php

Google Calendar API v3 cant add event php

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  <?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('[email protected]');
//$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 证书。

此链接中有一些信息描述了如何解决问题。

基本上,您需要在 Windows 机器上安装 CA 包,然后在代码中添加一行,告诉它在哪里寻找 CA 包。


一些程序已经有 CA 包。

在遇到此问题之前,我曾使用过 GIT 证书包。