C
C
CapitanFreeloader2016-10-15 13:01:51
YouTube
CapitanFreeloader, 2016-10-15 13:01:51

How to get the description of a video on YouTube by url?

Now I do this (I will reduce it to a minimum):

$id = /*id ролика*/;
$content = file_get_contents("http://youtube.com/get_video_info?video_id=$id");
parse_str($content, $ytarr);
print_r($ytarr);

So I get a huge amount of information, but I don’t get the description of the video. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2016-10-15
@CapitanFreeloader

go to https://console.developers.google.com , activate the tube API and create an API key for it.
and then everything is simple:

$id = /*id ролика*/;
$url = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$id&key=ваш-ключ";
$json = file_get_contents($url);
print_r(json_decode($json));

this will give output like this:
stdClass Object
(
    [kind] => youtube#videoListResponse
    [etag] => "I_8xdZu766_FSaexEaDXTIfEWc0/1GRTHrSXUwp9mfSo8btF2dBTfcA"
    [pageInfo] => stdClass Object
        (
            [totalResults] => 1
            [resultsPerPage] => 1
        )

    [items] => Array
        (
            [0] => stdClass Object
                (
                    [kind] => youtube#video
                    [etag] => "I_8xdZu766_FSaexEaDXTIfEWc0/W9riw6RqmQiwZM4L-fC7SglXIb4"
                    [id] => fVJJ8nzKamU
                    [snippet] => stdClass Object
                        (
                            [publishedAt] => 2014-05-26T21:50:59.000Z
                            [channelId] => UCIM_P-ohGAVGDbZWSPBs1Qw
                            [title] => Chris Isaak - Wicked Game (Gemma Hayes remix)
                            [description] => Absolute - Experience Music like never before.
» Facebook: http://on.fb.me/15wB9rV
» Twitter: http://bit.ly/17eu7Xf
                            [thumbnails] => stdClass Object
                                (
                                    [default] => stdClass Object
                                        (
                                            [url] => https://i.ytimg.com/vi/fVJJ8nzKamU/default.jpg
                                            [width] => 120
                                            [height] => 90
                                        )

                                    [medium] => stdClass Object
                                        (
                                            [url] => https://i.ytimg.com/vi/fVJJ8nzKamU/mqdefault.jpg
                                            [width] => 320
                                            [height] => 180
                                        )

                                    [high] => stdClass Object
                                        (
                                            [url] => https://i.ytimg.com/vi/fVJJ8nzKamU/hqdefault.jpg
                                            [width] => 480
                                            [height] => 360
                                        )

                                    [standard] => stdClass Object
                                        (
                                            [url] => https://i.ytimg.com/vi/fVJJ8nzKamU/sddefault.jpg
                                            [width] => 640
                                            [height] => 480
                                        )

                                    [maxres] => stdClass Object
                                        (
                                            [url] => https://i.ytimg.com/vi/fVJJ8nzKamU/maxresdefault.jpg
                                            [width] => 1280
                                            [height] => 720
                                        )

                                )

                            [channelTitle] => Absolute
                            [tags] => Array
                                (
                                    [0] => absolute
                                    [1] => deep
                                    [2] => dance
                                    [3] => house
                                    [4] => music
                                    [5] => 2013
                                    [6] => the
                                    [7] => beat
                                    [8] => lounge
                                    [9] => chill
                                    [10] => theabsolutebeat
                                    [11] => Lounge Music (Musical Genre)
                                    [12] => House Music (Musical Genre)
                                    [13] => chris isaak
                                    [14] => wicked game
                                    [15] => gemma
                                    [16] => hayes
                                    [17] => remix
                                    [18] => majesticcausal
                                )

                            [categoryId] => 24
                            [liveBroadcastContent] => none
                            [localized] => stdClass Object
                                (
                                    [title] => Chris Isaak - Wicked Game (Gemma Hayes remix)
                                    [description] => Absolute - Experience Music like never before.
» Facebook: http://on.fb.me/15wB9rV
» Twitter: http://bit.ly/17eu7Xf
                                )

                        )

                )

        )

)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question