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!