Google api php client - error on loading controlle

2019-06-11 17:31发布

问题:

I have used example from this site.

I have just added the credentials and the line:

require_once APPPATH . "libraries/google-api-php-client-master/src/Google/autoload.php";

in the controller.

It gives the following error :

Fatal error: Uncaught exception 'Exception' with message 'This library must be installed via composer or by downloading the full package. See the instructions at https://github.com/google/google-api-php-client#installation.' in /var/www/html/gauth/application/libraries/google-api-php-client-master/src/Google/autoload.php:14 Stack trace: #0 /var/www/html/gauth/application/controllers/user_authentication.php(15): require_once() #1 [internal function]: User_Authentication->index() #2 /var/www/html/gauth/system/core/CodeIgniter.php(360): call_user_func_array(Array, Array) #3 /var/www/html/gauth/index.php(202): require_once('/var/www/html/g...') #4 {main} thrown in /var/www/html/gauth/application/libraries/google-api-php-client-master/src/Google/autoload.php on line 14

Please help, I am doing this for the first time!

回答1:

It is because your project missed the lib google-api-php-client,suggest you install it via composer.

steps:

  • install composer (if you don't have)
  • add google-api-php-client lib to your project
  • rerun your code

steps in command

  • php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php php -r "if (hash('SHA384', file_get_contents('composer-setup.php')) === 'fd26ce67e3b237fffd5e5544b45b0d92c41a4afe3e3f778e942e43ce6be197b9cdc7c251dcde6e2a52297ea269370680') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); }" php composer-setup.php php -r "unlink('composer-setup.php');"

  • composer require google/apiclient:^2.0.0@RC

reference

  • composer
  • google-api-php-client