Search code examples
phpgoogle-api-php-client

Class not found while trying to load YouTube PHP API


I've been trying to load up the YouTube API (via Google Client v2.5), but I keep running into an error:

"error_message": "Class 'Google_Service_YouTube_Resource_Activities' not found",
"location": "[path snip]\/external\/google\/apiclient-services\/src\/Google\/Service\/YouTube.php:100"

As a test, I tried running the basic example on the GitHub page, and the Books API loaded correctly. (The request failed because the Books scope isn't registered to my API key, but it did load properly and attempt the call.) So, the autoload seems to be working, except that the YouTube API just gets stuck here every single time.

The code trying to load the API is inside the constructor of a class that's inside a namespace:

    $this->gclient = new \Google_Client();
    $this->gclient->setApplicationName($settings['appname']);
    $this->gclient->setDeveloperKey($settings['apikey']);
    $this->gclient->addScope(\Google_Service_YouTube::YOUTUBE_READONLY);

    $this->yclient = new \Google_Service_YouTube($this->gclient);

The libraries were installed via PHP Composer, and the vendor path was modified to external using its options. The server is running PHP 7.3.19.


Solution

  • Turns out, the problem was with file permissions. It works now, after running chmod to fix things up.