【发布时间】:2014-12-04 17:02:43
【问题描述】:
我几天来一直在尝试让 Google 的 Calendar PHP API 在我当地的 Laravel 开发网站上运行。问题来了:
我正在使用服务帐户,因此我可以在一个日历(服务帐户日历)上执行功能。我没有对用户进行身份验证并请求访问他们的日历。
我已经验证了我的客户 ID、服务电子邮件地址、key.P12 文件中的所有内容,但仍然没有任何反应。
这是我的代码:
$key = File::get($this->key);
$credentialObj = new \Google_Auth_AssertionCredentials(
$this->serviceAccountName,
array('https://www.googleapis.com/auth/calendar'),
$key,
'notasecret'
);
$client = new \Google_Client();
$client->setApplicationName($this->applicationName);
$client->setClientId($this->clientId);
$client->setAssertionCredentials($credentialObj);
\session_start();
$calendarServiceObj = new \Google_Service_Calendar($client);
$events = $calendarServiceObj->events->listEvents('mygmail@gmail.com');
dd($events->getItems());
我什至在这里尝试使用 Google 自己的示例:
https://github.com/google/google-api-php-client/blob/master/examples/service-account.php
没有错误,什么都没有。每次只是一个空白的错误页面。我在整个互联网上尝试了很多示例,甚至在堆栈溢出时,最后,我得到的只是“此网页不可用”。这发生在每个浏览器上。
Laravel 设置为开发模式,因此会显示所有错误,我什至使用 ini_set("display_errors", 1); 强制设置了 ini。
我知道一切正常,直到我从服务对象请求任何东西。在我的开发者帐户中,所有日历 api 都设置为 on。我的本地开发域是否需要启用 SSL?
如果我至少能弄清楚发生了什么,那就太好了,但是由于这个晦涩的错误,我不知道。
如果有人有任何提示,我将不胜感激。谢谢!!
编辑:我浏览了谷歌的 API 代码,这正是请求失败的地方:
vendor\google\apiclient\src\Google\Signer\P12.php
第 77 到 92 行:
public function sign($data)
{
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
throw new Google_Auth_Exception(
"PHP 5.3.0 or higher is required to use service accounts."
);
}
$hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256";
//If I die(); here, I receive the response
if (!openssl_sign($data, $signature, $this->privateKey, $hash)) {
//Something happens here, or inside the openssl_sign command, I never reach the exception
throw new Google_Auth_Exception("Unable to sign data");
}
//It never reaches here
return $signature;
}
在我的 PHP 信息中:
【问题讨论】:
标签: php laravel laravel-4 google-api google-calendar-api