@CapitanFreeloader

Как получить описание ролика на ютубе по url?

Сейчас делаю так (сокрачу до минимума):
$id = /*id ролика*/;
$content = file_get_contents("http://youtube.com/get_video_info?video_id=$id");
parse_str($content, $ytarr);
print_r($ytarr);

Так я получаю огроменное количество информации, но не получаю описание ролика. Как это можно сделать?
  • Вопрос задан
  • 1260 просмотров
Решения вопроса 1
DevMan
@DevMan
идете в https://console.developers.google.com, активируете API тюбика и создаете для него API key.
а дальше все просто:
$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));

это даст примерно такой выхлоп:
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
                                )

                        )

                )

        )

)

Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы