【问题标题】:I can't connect to google APIs with the PHP client library我无法使用 PHP 客户端库连接到 Google API
【发布时间】:2018-03-22 18:44:20
【问题描述】:

我无法使用 PHP 客户端库连接到 Google API。

我从 google 的服务帐户的入门页面开始。但我被这个错误困住了,女巫并没有告诉我很多关于这个问题的信息

我还尝试了库的 2.1.3 版本,结果相同。

这是我的代码。

<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
require_once __DIR__ . '/../library/google-api-php-client-2.2.0/vendor/autoload.php';

putenv('GOOGLE_APPLICATION_CREDENTIALS=./../secure/some-name-v2-cad7d18fcade.json');

$client = new Google_Client();
$client->useApplicationDefaultCredentials();

$driveService = new Google_Service_Drive($client);

$fileId = "0B9w-wSwYgo9ZU0toRFc3R1A5dlG";
$optParams = array();
$response = $driveService->files->get($fileId, $optParams); // Error on this line.

var_dump($response);
?>

致命错误:未捕获的错误:调用未定义的函数 Firebase\JWT\openssl_sign() C:\www\library\google-api-php-client-2.2.0\vendor\firebase\php-jwt\src\JWT.php:196

堆栈跟踪:

#0 C:\www\library\google-api-php-client-2.2.0\vendor\firebase\php-jwt\src\JWT.php(167): Firebase\JWT\JWT::sign('eyJ0eXAiOiJKV1Q...', '-----BEGIN PRIV...', 'RS256')

#1 C:\www\library\google-api-php-client-2.2.0\vendor\google\auth\src\OAuth2.php(1267): Firebase\JWT\JWT::encode(Array, '-----BEGIN PRIV...', 'RS256')

#2 C:\www\library\google-api-php-client-2.2.0\vendor\google\auth\src\OAuth2.php(418): Google\Auth\OAuth2->jwtEncode(Array, '-----BEGIN PRIV...', 'RS256')

#3 C:\www\library\google-api-php-client-2.2.0\vendor\google\auth\src\OAuth2.php(451): Google\Auth\OAuth2->toJwt()

#4 C:\www 在 C:\www\library\google-api-php-client-2.2.0\vendor\firebase\php-jwt\src\JWT.php 第 196 行

【问题讨论】:

    标签: php firebase google-api-php-client


    【解决方案1】:

    您缺少 openssl 扩展。

    取消注释(删除 ; 上的)您的 php.ini 中显示的行

    ;extension=php_openssl.dll
    

    然后重启你的服务器。

    【讨论】:

      猜你喜欢
      • 2016-12-08
      • 2015-08-19
      • 2018-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      相关资源
      最近更新 更多