Google API PHP 客户端库的问题
Problems with Google API Client Library for PHP
我正在尝试将 Google 的 API PHP 客户端库与我的应用程序集成,以验证某些令牌是否真实。
根据他们的说明,有两种方法可以做到这一点。
首先是使用 composer,我没有使用它,其次是从 https://github.com/google/google-api-php-client/ 下载 zip 文件并将其移动到服务器中的某个位置;我做到了。到目前为止,还不错。
然后,根据Google,
Uncompress the zip file you download, and include the autoloader in your project:
require_once '/path/to/google-api-php-client/vendor/autoload.php';
这样做的主要原因是运行下面的代码进行检查。
// Get $id_token via HTTPS POST.
$client = new Google_Client(['client_id' => $CLIENT_ID]);
$payload = $client->verifyIdToken($id_token);
if ($payload) {
$userid = $payload['sub'];
// If request specified a G Suite domain:
//$domain = $payload['hd'];
} else {
// Invalid ID token
}
但是,我从以下行收到致命错误:
require_once 'require_once '/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php';
使用 error_reporting(E_ALL);
和 ini_set('display_errors', 1);
的错误是:
<br />
<b>Warning</b>: require_once(/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php): failed to open stream: No such file or directory in <b>/var/www/html/php/insert.php</b> on line <b>7</b><br />
<br />
<pre>
<b>Fatal error</b>: require_once(): Failed opening required '/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php' (include_path='.:/usr/share/php') in <b>/var/www/html/php/insert.php</b> on line <b>6</b><br />
</pre>
目前,我的 insert.php 代码是:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include_once ('/var/www/db/connection.php');
require_once '/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php';
$value = json_decode(file_get_contents('php://input'));
?>
我可能做错了什么?
在继续之前,请检查指定路径中是否存在文件autoload.php。
然后,您可以下载并使用发布包,因为您链接的 GitHub 存储库是与 composer 一起使用的。发布包可以在 Google Releases
找到
我正在尝试将 Google 的 API PHP 客户端库与我的应用程序集成,以验证某些令牌是否真实。
根据他们的说明,有两种方法可以做到这一点。 首先是使用 composer,我没有使用它,其次是从 https://github.com/google/google-api-php-client/ 下载 zip 文件并将其移动到服务器中的某个位置;我做到了。到目前为止,还不错。
然后,根据Google,
Uncompress the zip file you download, and include the autoloader in your project: require_once '/path/to/google-api-php-client/vendor/autoload.php';
这样做的主要原因是运行下面的代码进行检查。
// Get $id_token via HTTPS POST.
$client = new Google_Client(['client_id' => $CLIENT_ID]);
$payload = $client->verifyIdToken($id_token);
if ($payload) {
$userid = $payload['sub'];
// If request specified a G Suite domain:
//$domain = $payload['hd'];
} else {
// Invalid ID token
}
但是,我从以下行收到致命错误:
require_once 'require_once '/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php';
使用 error_reporting(E_ALL);
和 ini_set('display_errors', 1);
的错误是:
<br />
<b>Warning</b>: require_once(/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php): failed to open stream: No such file or directory in <b>/var/www/html/php/insert.php</b> on line <b>7</b><br />
<br />
<pre>
<b>Fatal error</b>: require_once(): Failed opening required '/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php' (include_path='.:/usr/share/php') in <b>/var/www/html/php/insert.php</b> on line <b>6</b><br />
</pre>
目前,我的 insert.php 代码是:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include_once ('/var/www/db/connection.php');
require_once '/var/www/html/various/google-api-php-client-2.1.1/vendor/autoload.php';
$value = json_decode(file_get_contents('php://input'));
?>
我可能做错了什么?
在继续之前,请检查指定路径中是否存在文件autoload.php。
然后,您可以下载并使用发布包,因为您链接的 GitHub 存储库是与 composer 一起使用的。发布包可以在 Google Releases
找到