phpgoogle-analytics

Google API PHP client


I'm trying to implement the Google Analytics API on the localhost site using XAMPP on macOS.

But I’m getting this error:

Fatal error: Uncaught Exception: 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 /Applications/XAMPP/xamppfiles/htdocs/ga-api/google-api-php-client/autoload.php:14 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/ga-api/index.php(4): require_once() #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/ga-api/google-api-php-client/autoload.php on line 14

How can I fix this?


Solution

  • Given that you installed the library using Composer, it will be installed to vendor and will be available in the autoload.php that Composer generates.

    I will require_once DIR. '/vendor/autoload.php'; in index.php (preferred) or where I need to instantiate the GoogleClient class.

    Ensure that the path to client credentials are rightly referenced when you set auth config like so: Google_Client->setAuthConfig($pathToCredentials)

    Reference: