0

I am developing a web page and I have a small problem with the YouTube API. I want to get all the information of any YouTube video, but I can not get the data. I have the following PHP code to make the request to the server:

Here is my Code:

$video_get_contents = file_get_contents('https://www.googleapis.com/youtube/v3/videos?part=snippet&id=J643lwa-BlM&key=AIzaSyATfzheNPybhDYRIgLwQw__rjE8XddZP8s');
$video_data = json_decode($video_get_contents);
$video_data_title = $video_data->items[0]->snippet->title;
echo $video_data_title;

When I run the previous code I do not get anything, and I do not know why. If I access the URL specified in the code, the JSON code is generated correctly.

When executing my code I get these errors:

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\xampp\htdocs\beta.php on line 4
Warning: file_get_contents(): Failed to enable crypto in C:\xampp\htdocs\beta.php on line 4
Warning: file_get_contents(https://www.googleapis.com/youtube/v3/videos?part=snippet&id=J643lwa-BlM&key=AIzaSyATfzheNPybhDYRIgLwQw__rjE8XddZP8s): failed to open stream: operation failed in C:\xampp\htdocs\beta.php on line 4

Could you tell me if the PHP code is correct?

1 Answers1

0

you cant access https url with the file_get_contents, however for youtube API you can access it using the example in https://developers.google.com/youtube/v3/code_samples/php and if you still want to access the json in your url, here is a similar question about how to access https with file get contents file_get_contents(): SSL operation failed with code 1. And more

Kareem Essawy
  • 565
  • 1
  • 4
  • 14