php - PHP 致命错误:未捕获的错误:在 .../Client.php:954 中找不到类“Google\Auth\OAuth2”
问题描述
以下线程不能为我解决它: -
致命错误:未捕获的错误:找不到类“Google_Client”
甚至这个:-
实现 Oauth2 登录,致命错误:找不到类“Google_Service”
大家好,
error_log 中的确切日志如下:-
PHP Fatal error: Uncaught Error: Class 'Google\Auth\OAuth2' not found in /home/.../public_html/.../google/Client.php:954
Stack trace:
#0 /home/.../public_html/.../google/Client.php(943): Google_Client->createOAuth2Service()
#1 /home/.../public_html/.../google/Client.php(338): Google_Client->getOAuth2Service()
#2 /home/.../public_html/.../logintest.php(39): Google_Client->createAuthUrl()
#3 {main}
thrown in /home/.../public_html/.../google/Client.php on line 954
以下是 Client.php 中的几行
public function getOAuth2Service()
{
if (!isset($this->auth)) {
$this->auth = $this->createOAuth2Service();
}
return $this->auth;
}
/**
* create a default google auth object
*/
protected function createOAuth2Service()
{
$auth = new OAuth2(
[
'clientId' => $this->getClientId(),
'clientSecret' => $this->getClientSecret(),
'authorizationUri' => self::OAUTH2_AUTH_URL,
'tokenCredentialUri' => self::OAUTH2_TOKEN_URI,
'redirectUri' => $this->getRedirectUri(),
'issuer' => $this->config['client_id'],
'signingKey' => $this->config['signing_key'],
'signingAlgorithm' => $this->config['signing_algorithm'],
]
);
return $auth;
}
堆栈跟踪的第 3 行(对我而言)表明 autoload.php 和 Client.php 的包含已正确完成
我在共享主机上,这就是我无法通过 Composer 安装的原因。我只是下载并复制了文件(根据https://github.com/googleapis/google-api-php-client#installation)。
这就是我包含文件的方式
set_include_path(get_include_path() . PATH_SEPARATOR . '/../google/');
include_once __DIR__ . '/../google/autoload.php';
require_once 'google/Client.php';
require_once 'google/Service.php';
PHP代码中以下行的错误触发器:-
$url = $client->createAuthUrl();
请帮忙!
解决方案
推荐阅读
- windows - 在 Win10 上创建快捷方式失败 accessdenied
- javascript - 使用其对话框添加链接时出现 EmebrJS + CKEDITOR 错误
- java - JSON到POJO作为使用jackson java的对象类
- sass - 使图像与另一个图像水平对齐。Flexbox 我不认为是答案。我想我需要某种 scss calc()
- python-3.x - Python Pandas - 新列返回每个唯一 ID 的最早数据
- reactjs - 在 React App 中使用 Knex JS 获取失败
- php - 如何在单独的行中将数组索引数据保存到数据库中?
- deep-learning - 为什么我在 CIFAR10 数据集上训练的 resnet110 只能获得 77% 的测试结果
- android - “int”类型不是“double”类型的子类型
- c# - 在构造函数中使用 IDataRecord 来初始化对象(实体)是个好主意吗?