0

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.

2 Answers2

0

Im not sure what gclient and yClient are.

For starters you appear to have forgotten to add your client secret json file. Im not sure which method you are going to use but most of the youtube api is going to require authentication. You only have an api key there that will only work on public methods.

$client = new Google_Client();
$client->setAccessType("offline");        // offline access.  Will result in a refresh token
$client->setIncludeGrantedScopes(true);  
$client->setAuthConfig(__DIR__ . '/client_secrets.json');
$client->addScope([YOUR SCOPES HERE]);
$client->setRedirectUri(getRedirectUri());  

$service = new Google_Service_Youtube($client); 
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Suppose I only need access to public data. Playlists and videos that have been published and are publicly available. In any case, the issue is not with accessing the API, but creating the PHP service itself. – FelicitusNeko Jun 16 '20 at 14:52
0

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