google-api-php-client: Fatal error: Class 'Google_Client' not found
Api installed manually, not via Composer, downloaded from here (first zip): https://github.com/google/google-api-php-client/releases
I got this error, trying to instantiate the main class: Fatal error: Class ‘Google_Client’ not found
- Php “require_once” looks ok (no error).
- Json’s credentials looks ok (no error).
- Class instance not ok.
require_once('./vendor/autoload.php'); putenv('GOOGLE_APPLICATION_CREDENTIALS=./mycredentials.json'); $client = new Google_Client(); $client->useApplicationDefaultCredentials(); $client->setScopes('https://www.googleapis.com/auth/fusiontables'); $service = new Google_Service_Fusiontables($client);
This is the source code I can see in /vendor/autoload.php `<?php
// autoload.php @generated by Composer
require_once DIR . ‘/composer’ . ‘/autoload_real.php’;
return ComposerAutoloaderInit9c18b0e2f8ac75b5fbc347bb34dca41d::getLoader();`
Any hint?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 31 (5 by maintainers)
I had the same issue in laravel and solved it by importing the Google_Client :
use Google_Client;
Whoops, /src folder missing… thanks @bshaffer
check the file composer.json
and add “vendor/google/apiclient/src/Google” in classmap array if not exist.
and run
composer dump-autoload
Hey @simonericci Can you do an
ls -la
in your root directory? It’s possible you’re in the wrong directory, and so pulling in a differentvendor/autoload.php
than the one required in this library. Also, perform anls -la src/Google
to verify theClient.php
file exists where it should be.Try this:
if you have “vendor/google/apiclient/src/Google” directory and still you get this error try use command.
use Google_Client;
@induraniv @Wakodebe @garciacarmonaam @luispinonferrer-capgemini Google_Client is located in src/Google/Client.php of the package archive.
The error ‘Fatal error: Class ‘Google_Client’ not found’ indicates that Client.php was not included/required explicitly or automatically. That is typically due to a line like
not resolving to the correct location (in the package archive: vendor/autoload.php). The path of autoload is relative any file with this line so make sure to account for that if you paste this line into other files.