1

The following threads do not solve it for me:-

Fatal error: Class 'Google\Auth\OAuth2' not found

Class 'Google\Auth\OAuth2' not found

Fatal error: Uncaught Error: Class 'Google_Client' not found

and even this one:-

Implementing Oauth2 login, Fatal error: Class 'Google_Service' not found

Hi everyone,

The exact logs from the error_log are below:-

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

Below are a few lines from the 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;
  }

Line #3 of the stack trace indicates (to me) that the inclusion of autoload.php and Client.php is done correctly

I am on shared hosting which is why I could not install via Composer. I just download and copied the files (as per https://github.com/googleapis/google-api-php-client#installation).

This is how I included the files

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';

The error trigger at the following line in the PHP code:-

$url = $client->createAuthUrl();

Please help!

burf
  • 25
  • 1
  • 7
  • Even on shared hosting it is possible to use composer correctly, install locally, test locally, upload to webspace, test there again. Working directly on a shared hosting does more bad than good. – Michael B. May 31 '19 at 08:35
  • @MichaelB. sounds like the correct approach – burf May 31 '19 at 08:37
  • ok then let's trace the problem, you downloaded from the releases? https://github.com/googleapis/google-api-php-client/releases you named the extracted folder "google"? did you get a warning `autoload.php` not found? try change the `include_once` to a `require_once`, the `autoload.php` is in `vendor` inside the released zip, remove the other two `require_once`. – Michael B. May 31 '19 at 08:56
  • The ZIP file that is download from https://github.com/googleapis/google-api-php-client.git has the following `\google-api-php-client-master\src\Google` path where `autoload.php` and `Client.php` and others are present. I don't see any `vendor` directory there – burf May 31 '19 at 09:03
  • You need to download the release and not the Git repo, https://github.com/googleapis/google-api-php-client#download-the-release – Michael B. May 31 '19 at 09:06
  • I did that too, the path and files are almost identical `\google-api-php-client-2.2.3\src\Google` – burf May 31 '19 at 09:08
  • Almost is the point ;) In the release is the `vendor` and `src` folder, you need to `require` the `google-api-php-client/vendor/autoload.php`, there everything is wired and you are ready to use the classes. – Michael B. May 31 '19 at 09:11
  • it works! thanks a lot @MichaelB. it was really stupid of me to not scroll down to the list of downloadable files. the one that i downloaded *now* was listed under section "Assets" on the link - `https://github.com/googleapis/google-api-php-client/releases/download/v2.2.3/google-api-php-client-2.2.3.zip` and the compressed size was 10.8 MB, as mentioned. – burf May 31 '19 at 09:34

0 Answers0