Getting title and description of embedded YouTube video

后端 未结 7 1776
抹茶落季
抹茶落季 2021-02-05 12:36

On a site I\'m developing I embed videos from YouTube and want to get the video title and its description.

How do I get that information?

7条回答
  •  轮回少年
    2021-02-05 12:51

    I read this topic a bit in delay. I did something like this using jSON and YT API's

    $json = json_decode( file_get_contents("http://gdata.youtube.com/feeds/api/videos/".$rs['vid']."?v=2&prettyprint=true&alt=jsonc") );
    

    Note: $rs['vid'] is the video ID dinamically retrived from my DB.

    Once you put the contents in the handle $json you can retrive like this:

    $json->data->description;
    $json->data->title;
    

    use var_dump( $json ) to view all values you can access.

提交回复
热议问题