首页 > 解决方案 > PHP 致命错误:未捕获的错误:在 .../Client.php:954 中找不到类“Google\Auth\OAuth2”

问题描述

以下线程不能为我解决它: -

致命错误:找不到类“Google\Auth\OAuth2”

找不到类“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();

请帮忙!

标签: phpgoogle-oauth

解决方案


推荐阅读