Search code examples
phpyoutube-apigoogle-client

PHP Youtube Data API: Uncaught exception: This library must be installed via composer or by downloading the full package


I am trying to access the Youtube Data API using the Google Client library with the quickstart samplecode from Google for webserver-use with PHP. But im having trouble installing the client library, as i have used the method to download the entirely folder by its files from Github.

In the quickstart sample code and install guide for Google Client library, their path for requiring the autoload.php file includes a folder named vendor, where the autoload.php file is inside.

If you downloaded the package separately, your require statement will look like this: require_once '/path/to/google-api-php-client/vendor/autoload.php';

This folder does not exist in the library files at Github.

I therefore tried to make the filestructure as they require, by copying the autoload.php file from google-api-php-client/src/google/ to a new folder named vendor inside google-api-php-client.

When executing the quickstart.php file, this error occurs:

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 path\to\project\google-api-php-client\vendor\autoload.php:14 Stack trace: #0 path\to\project\quickstart.php(11): require_once() #1 {main} thrown in path\to\project\google-api-php-client\vendor\autoload.php on line 14

This is the file structure im using:
project folder
    google-api-php-client folder
    src folder
    vendor folder
       autoload.php file
client_secrets.json file
quickstart.php file

There is an duplicate of this thread here: Missing vendor/autoload.php in google-api-php-client-master but its not solved so im looking for answers that can help solve this issue.


Solution

  • I solved it. The Api Client library must be downloaded from here https://github.com/google/google-api-php-client/releases and not https://github.com/google/google-api-php-client.

    It seemed like the folder on the page itself was good enough but that you could get a better one from the releases, but this was not the case, as its only the versions on releases thats supposed to be used if you dont use the composer method.