谷歌日历API我一直在尝试了几天让谷歌的日历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('[email protected]');
dd($events->getItems());
我甚至已经在这里使用谷歌自己的例子尝试:
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信息: