【问题标题】:Google API Calendar谷歌 API 日历
【发布时间】:2016-04-15 08:30:46
【问题描述】:

这是我为从 Google 日历获取日历事件而编写的代码。在 localhost 中运行它时,它需要用户的许可,但显示

致命错误:未捕获异常 'GuzzleHttp\Exception\RequestException' 并在 D:\wamp\www\google-api 中显示消息“cURL 错误 60:SSL 证书问题:无法获取本地颁发者证书(请参阅 http://curl.haxx.se/libcurl/c/libcurl-errors.html)” -php-client-2.0.0-RC4\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php 在第 187 行

(!) GuzzleHttp\Exception\RequestException:cURL 错误 60:SSL 证书问题:无法在 D:\wamp\www\google-api-php-client-2.0 中获取本地颁发者证书(请参阅 http://curl.haxx.se/libcurl/c/libcurl-errors.html)。 0-RC4\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php 在第 187 行

我尝试在 php.ini 中添加 cacert.pem 路径以及其他论坛上提到的其他内容。没有任何效果。我尝试将文件在线放在服务器(Centos)中。也安装了作曲家。 但是在那里,当我尝试加载页面时,什么都没有显示。

据我所知,Google api 包供应商内部的 autoload.php 没有返回任何内容。

返回 ComposerAutoloaderInitd82ee48119182e2321ebd694e70287c2::getLoader();

我哪里错了?或者,代码有问题吗?

session_start();
require_once './google-api-php-client-2.0.0-RC4/vendor/autoload.php';
set_include_path(get_include_path() . PATH_SEPARATOR . './google-api-php-client-2.0.0-RC4/src');
$google_client_id = '...';
$google_client_secret = '...';
$google_redirect_uri = 'http://localhost/gapicc.php';
$client = new Google_Client();
$client -> setApplicationName('Sample');
$client -> setClientid($google_client_id);
$client -> setClientSecret($google_client_secret);
$client -> setRedirectUri($google_redirect_uri);
$client -> setAccessType('online');
$client -> setScopes(Google_Service_Calendar::CALENDAR);
$googleImportUrl = $client -> createAuthUrl();
if(isset($_GET['code']))
{
    $auth_code = $_GET['code'];
    $client->authenticate($_GET['code']);
    $access_token = $client->getAccessToken();
    $calendar_service = new Google_Service_Calendar($client);
    $calendar_list = $calendar_service->calendarList->listCalendarList(array())->getItems();
    echo json_encode($calendar_list);
}

echo filter_var($googleImportUrl, FILTER_SANITIZE_URL); // 当用户点击“导入 Google 日历”时,我指向用户的路径

【问题讨论】:

  • 您查看过 Google 日历 API 的 PHP Quickstart 吗?您的开发者控制台中是否启用了日历 API?

标签: ssl curl calendar google-calendar-api google-api-js-client


【解决方案1】:

可以使用不带 SSL 的 URL 作为重定向 URL。本地主机也是允许的。 问题可能出在 auth 或 token URL 中

  1. 检查限制您在此处键入https://console.developers.google.com/apis/credentials

  2. 尝试从那里使用 credentials.json 来设置 ClientID 和 ClientSecret。 它也有 auth_uri 和 token_uri。

    为此,请使用全新的 google API 日历快速入门 https://github.com/gsuitedevs/php-samples/tree/master/calendar/quickstart 作为所有步骤的帮助。

    使用最新版本的 google API(现在为 2.2.2) https://github.com/googleapis/google-api-php-client/releases

【讨论】: