3

I have create a component :

<?php
    namespace common\components;
    use Google_Client;
    use Google_Service_Gmail;
    use Yii;
    use yii\base\ErrorException;
    use yii\helpers\ArrayHelper;
    use yii\base\Component;

    use yii\rest\ActiveController;
    use linslin\yii2\curl;



    class SocialLogin extends Component {
      public $GOOGLE_CLIENT_ID;
      public $FACEBOOK_CLIENT_ID;
      public $GOOGLE_CLIENT_ID_IOS;




      public function getGoogleUser($id_token,$device)
      {
            $clientID=$this->GOOGLE_CLIENT_ID;

            if($device=="ios")
            $clientID=$this->GOOGLE_CLIENT_ID_IOS;

            $client = new Google_Client(['client_id' => $clientID]);
            $payload = $client->verifyIdToken($id_token);
            if ($payload) {
                    // my code
            }

        }    

   }

Its working fine on local but on live server i'm getting following error :

message": "Class 'Google_Client' not found",

What will be the issue ?

Arunendra
  • 570
  • 2
  • 10
  • 34

4 Answers4

2

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"
        ]
}
tushar zore
  • 101
  • 1
  • 8
1

If you already required the composer autoload.php and require the google/apiclient composer package, you can search vendor/composer/autoload_static.php for:

'Google_' => 
    array (
        0 => __DIR__ . '/..' . '/google/apiclient/src',
    ),

This is google/apiclient PSR-0 map, if you don't find it or the path is wrong, it means that the google/apiclient package is not install correctly.

Hope this could help you.

Nick Tsai
  • 3,799
  • 33
  • 36
  • I found that exactly entry. Though I had include 7 uses in my component file in order to work. I don't have much time for this google task and I wonder if there isn't a use Google/*; or something. – Matheus May 23 '18 at 13:12
1

I have solved the issue. The issue was PHP version, it was PHP 7 on my local machine and on server it was 5.6 then I have updated the PHP version and all problems are gone.

Arunendra
  • 570
  • 2
  • 10
  • 34
1

Include below code in composer.json file in your root directory.

 {
    "require": {
        "google/apiclient": "^2.0"
      }
   }

And then run command: composer update

This will create a folder google in your vendor directory at root level. Inside this google folder there are subfolders of apiclient, apiclient-services and auth.

  • You can generate the composer.json file with `composer require google/apiclient`. At time of writing, it will give you version `"^2.12"`. – mwfearnley Jan 07 '22 at 17:04