Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Class 'Google_Client' not found #1214

Closed
simonericci opened this issue May 5, 2017 · 31 comments
Closed

Fatal error: Class 'Google_Client' not found #1214

simonericci opened this issue May 5, 2017 · 31 comments
Assignees

Comments

@simonericci
Copy link

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?

@bshaffer
Copy link
Contributor

bshaffer commented May 5, 2017

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.

@simonericci
Copy link
Author

Whoops, /src folder missing... thanks @bshaffer

@induraniv
Copy link

Class 'vendor\Google\src\Google\Google_Client' not found
Api installed manually, not via Composer.

@Wakodebe
Copy link

Wakodebe commented Sep 9, 2018

I have the same problem, but havent find a solution yet

@Wakodebe
Copy link

Wakodebe commented Sep 9, 2018

Any help

@garciacarmonaam
Copy link

Did somebody find out a solution finally?

@ravcing
Copy link

ravcing commented Nov 15, 2018

No description provided.

@lpinon
Copy link

lpinon commented Dec 2, 2018

Any solution ?

@mattwhisenhunt
Copy link
Contributor

@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.

@tusharzore1
Copy link

tusharzore1 commented Feb 27, 2019

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"
        ]
}

@bshaffer
Copy link
Contributor

bshaffer commented Feb 27, 2019

You should definitely not need to add an autoload directive to your composer.json. If you install via composer, including vendor/autoload.php will suffice. If you downloaded the library zip, you'll need to require the vendor/autoload.php file which exists inside that package.

@tusharzore1
Copy link

Yeah, Definitely.
But somehow laravel framework not able to find class Google_Client into autoload.php. It needs
class mapping via classmap array.

@bshaffer
Copy link
Contributor

bshaffer commented Mar 4, 2019

@tusharzore1 I do not know why in your specific case the class Google_Client isn't found, but I can tell you with certainty the class mapping should not need to be added to the classmap array.

@pokerpierre
Copy link

I had the same issue and when checking the autoload_namespaces.php file I noticed that the Google entry pointed to '/src'. I added that folder and the issue was resolved.

@kamleshwebtech
Copy link

require_once('/vendor/google-api-php-client-2.4.0/src/Google/autoload.php');
require_once('/vendor/google-api-php-client-2.4.0/vendor/autoload.php');

$client = new Google_Client();

I have checked the file path by file_exists function and included both the autoload files but system is still returning error:
Class 'Google_Client' not found

Please help to fix this issue.

@kamleshwebtech
Copy link

Is there anyone who can help me to fix this issue?

@suman-tms
Copy link

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

use Google_Client;

@pult
Copy link

pult commented Oct 10, 2019

install google/apiclient:

$ composer require google/apiclient

@tusharzore1
Copy link

tusharzore1 commented Oct 10, 2019

I had tried a customised solution for this situation, commented above.

@msozsari
Copy link

msozsari commented Dec 9, 2019

if you have "vendor/google/apiclient/src/Google" directory and still you get this error try use command.

use Google_Client;

@googleapis googleapis deleted a comment from yosus Mar 1, 2020
@DarshitAnjaria
Copy link

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

use Google_Client;

thank you very much this also solve the problem of mine...

@carolt00
Copy link

carolt00 commented Apr 21, 2020

Tuve el mismo problema en laravel y lo resolví importando Google_Client:
use Google_Client;

muchas gracias, esto también resuelve el problema mío ...

@DarshitAnjaria Hola, me puedes decir por favor en que parte lo pusiste?

@maalgorepublic
Copy link

Faced the same issue on Codeigniter, I was including autoload.php of require "\vendor\google\auth\autoload.php" this was causing the problem.
You don't need to map any class in composer, including autoload of vendor instead of google solved my problem.
require ('vendor\autoload.php')

@jyot53
Copy link

jyot53 commented Apr 3, 2021

if you have "vendor/google/apiclient/src/Google" directory and still you get this error try use command.

use Google_Client;

This "vendor/google/apiclient/src/Google" directory is not present after i installed composer

@dinhkhanh
Copy link

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.

@Shonu72
Copy link

Shonu72 commented Sep 20, 2021

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!!

@dinhkhanh
Copy link

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();

@bshaffer
Copy link
Contributor

bshaffer commented Sep 22, 2021

The base directories are now in vendor/google/apiclient/src and vendor/google/apiclient-services/src

If you use composer and include vendor/autoload.php, this change will not effect you. However, if you used some other mechanism such as include_dir, then this change may have broken your installation.

@wx05
Copy link

wx05 commented Sep 26, 2022

if you have "vendor/google/apiclient/src/Google" directory and still you get this error try use command.

use Google_Client;

thx bro~ i'm ok~

@rajithwijepura
Copy link

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();

Life saver. Thanks. This worked with CakePHP 4

@darshannv
Copy link

Please update the composer.json

 "google/apiclient": "^2.12.1"

Inside the composer.json file under the extra update this

 "extra": {
     "google/apiclient-services": [
        "Drive",
        "YouTube"
    ]
}

under the script section at the bottom add this line

"scripts": {
     "pre-autoload-dump": "Google\\Task\\Composer::cleanup"
 }

After adding it, run the command

composer update
composer dump-autoload 

It will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests