Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installing Google Client Library for Google Analtics PHP

first of all I am new to this topic, so I hope my question is not too stupid.

I want my website to have PHP access to Google Analytics metrics. I followed every step of this description from google. Unfortunately when I upload everything on my server and try to run the test-site, I always get the following error-message:

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 /home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php:14 Stack trace: #0 /home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(8): require_once() #1 /home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(104): getService() #2 {main} thrown in /home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php on line 14

So apparently there is something wrong with the embedding of the Google client library. In the error message it says I have to use Composer, but in the GitHub documentation they say, manual download would be fine as well. I think in the end this shouldn't make any difference? I am not familiar with composer or GitHub, this is why i downloaded it manually.

I uploaded it on the server and put it into the same directory like the HelloAnalytics.php. I address it in HelloAnalytics.php via

require_once 'google-api-php-client-master/src/Google/autoload.php'
like image 407
André GC Avatar asked Dec 18 '22 22:12

André GC


1 Answers

From the looks of it you are using the wrong autoloader.

src/Google/autoload.php looks for the composer autoloader and if it doesn't exist it throws the exception you are getting. Since you didn't install using Composer it is not found and that exception is thrown.

If you clone the repository using git you will have the correct SPL autoloader. If you download the package it uses the composer autoloader.

Try downloading using:

git clone -b v1-master https://github.com/google/google-api-php-client.git

Or switch to the v1-master branch and use this autoloader instead. You will see that file differs between the master branch and the v1-master branch.

like image 181
drew010 Avatar answered Dec 31 '22 01:12

drew010