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)

Most upvoted comments

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

"autoload": {
        "classmap": [
            "vendor/google/apiclient/src/Google"
        ]
}

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 different vendor/autoload.php than the one required in this library. Also, perform an ls -la src/Google to verify the Client.php file exists where it should be.

I had the same issue in laravel and solved it by importing the Google_Client : use Google_Client;

Save me! For more clearly, importing use Google_Client; and then, instead of using new \Google_Client();, use new Google_Client(); (without backslash). This also applies to any other Google classes, eg. Google_Services_Adsense.

I tried everything as you mentioned but still getting error!!

Try this:

use Google\Client;

....

$client = new Client();

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

include_once __DIR__ . '/../vendor/autoload.php';

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.