Retrieve and display YouTube video description, ti

2019-02-20 17:46发布

问题:

I would like to display on a page the title and description of a video youtube, I know how do this for count number with this php code

<?php
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?
part=statistics&id=videoID&key=APIKey");
$json_data = json_decode($JSON, true);
echo $json_data['items'][0]['statistics']['viewCount'];
?>

But i don't know how do this do display video title and description.

回答1:

<?php
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?
part=snippet&id=videoID&key=APIKey");
$json_data = json_decode($JSON, true);
echo $json_data['items'][0]['snippet']['title'];
echo $json_data['items'][0]['snippet']['description'];
?>