带有服务帐户问题的Google Calendar API

时间:2014-12-04 17:02:43

标签: php laravel laravel-4 google-api google-calendar-api

我一直在努力让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());

我甚至尝试过使用谷歌自己的例子:

https://github.com/google/google-api-php-client/blob/master/examples/service-account.php

没有错误,没有。每次只是一个空白的错误页面。我在互联网上尝试了很多这样的例子,即使是在堆栈溢出的情况下也是如此,最后,我得到的只是一个'这个网页不可用'。这种情况发生在每个浏览器上。

enter image description here

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信息中:

enter image description here

1 个答案:

答案 0 :(得分:0)

通过更新PHP解决。我使用的是Softaculous AMPP 2.3和PHP 5.4.27。升级到AMPP 2.6解决了这个问题。我的配置中的我的Open SSL现在是:

enter image description here

之后我的代码没有做任何事,现在它可以工作了。这绝对是一个开放的问题。任何收到ERR_CONNECTION_RESET的人都必须更新他们的open_ssl版本。

我希望这有助于任何人试图解决这个问题。

相关问题