Question

I'm experiencing a weird issue with the YouTube API v3 (with the php library) : When I send a request, it works, but only one time per request. If I ask for my 4 last uploads, it works, then if I ask for my 3 last uploads, it works, but if I ask again for my 4 last uploads, I get this :

An client error occurred: HTTP Error: Unable to connect: '0'

Here is my code :

<?php

require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';

$DEVELOPER_KEY = 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxx4RXo';

$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);




$youtube = new Google_Service_YouTube($client);

$uploadsListId = 'UUVoQooxxxxxxxxxAv7xag';



try 
{

$youtubeResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
'maxResults' => 1,
'playlistId' => $uploadsListId
  ));



} catch (Google_ServiceException $e) {
die('<p>A service error occurred: <code>'.htmlspecialchars($e->getMessage()).'</code></p>');
} catch (Google_Exception $e) {
die('<p>An client error occurred: <code>'.htmlspecialchars($e->getMessage()).'</code></p>');
}

?>

It's the first time that I use this API so maybe I'm missing something.

Can anyone help me ?

Was it helpful?

Solution

Looking at the youtube API library code in Google_IO_Stream and Google_IO_Abstract, you are getting the UNKNOWN_ERROR code, which is 0.

You can't know what the error is since the fopen call is suppressed at the Google_IO_Stream class (line 102). I suggest you remove the @ sign at the @$fh = fopen($url, 'r', false, $context); line and run your code again to get the error message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top