Return upcoming YouTube API V3 video schedule date?

ⅰ亾dé卋堺 提交于 2020-05-29 12:42:54

问题


I'm looking to return the schedule date for a stream in YouTube.

Example of scheduled streams:

YT Link: https://www.youtube.com/channel/UCP7jMXSY2xbc3KCAE0MHQ-A

This is my code to pull this data out using the YouTube v3 API:

        $videos = $this->yt->searchAdvanced(array(
            'q' => '',
            'part' => 'snippet',
            'channelId' => $this->channel_id,
            'eventType' => $event_type, // Upcoming
            'type' => 'video',
            'order' => 'date',
            'maxResults' => $max,
            'key' => YOUTUBE_API_KEY
        ));

Here is the object that is returned from this:

If I use my function to get video info this is all the information I can get. This is using parts:

id, snippet, contentDetails, player, statistics, status

: Where is the scheduled date? :

stdClass Object
(
    [kind] => youtube#video
    [etag] => "q5k97EMVGxODeKcDgp8gnMu79wM/KAZsrzeX5ImiUQpLbwhPR7lo9mA"
    [id] => qUAmTYHEyM8
    [snippet] => stdClass Object
        (
            [publishedAt] => 2016-03-03T06:48:50.000Z
            [channelId] => UCP7jMXSY2xbc3KCAE0MHQ-A
            [title] => Match 3 - Google DeepMind Challenge Match: Lee Sedol vs AlphaGo
            [description] => Watch DeepMind's program AlphaGo take on the legendary Lee Sedol (9-dan pro), the top Go player of the past decade, in a $1M 5-game challenge match in Seoul. This is the livestream for Match 3 to be played on: 12th March 13:00 KST (local), 04:00 GMT; note for US viewers this is the day before on: 11th March 20:00 PT, 23:00 ET. 

In October 2015, AlphaGo became the first computer program ever to beat a professional Go player by winning 5-0 against the reigning 3-times European Champion Fan Hui (2-dan pro). That work was featured in a front cover article in the science journal Nature in January 2016.

Match commentary by Michael Redmond (9-dan pro) and Chris Garlock.
            [thumbnails] => stdClass Object
                (
                    [default] => stdClass Object
                        (
                            [url] => https://i.ytimg.com/vi/qUAmTYHEyM8/default_live.jpg
                            [width] => 120
                            [height] => 90
                        )

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

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

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

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

                )

            [channelTitle] => DeepMind
            [categoryId] => 28
            [liveBroadcastContent] => upcoming
            [localized] => stdClass Object
                (
                    [title] => Match 3 - Google DeepMind Challenge Match: Lee Sedol vs AlphaGo
                    [description] => Watch DeepMind's program AlphaGo take on the legendary Lee Sedol (9-dan pro), the top Go player of the past decade, in a $1M 5-game challenge match in Seoul. This is the livestream for Match 3 to be played on: 12th March 13:00 KST (local), 04:00 GMT; note for US viewers this is the day before on: 11th March 20:00 PT, 23:00 ET. 

In October 2015, AlphaGo became the first computer program ever to beat a professional Go player by winning 5-0 against the reigning 3-times European Champion Fan Hui (2-dan pro). That work was featured in a front cover article in the science journal Nature in January 2016.

Match commentary by Michael Redmond (9-dan pro) and Chris Garlock.
                )

        )

    [contentDetails] => stdClass Object
        (
            [duration] => PT0S
            [dimension] => 2d
            [definition] => sd
            [caption] => false
            [licensedContent] => 1
        )

    [status] => stdClass Object
        (
            [uploadStatus] => uploaded
            [privacyStatus] => public
            [license] => youtube
            [embeddable] => 1
            [publicStatsViewable] => 1
        )

    [statistics] => stdClass Object
        (
            [viewCount] => 41
            [likeCount] => 1
            [dislikeCount] => 0
            [favoriteCount] => 0
            [commentCount] => 0
        )

    [player] => stdClass Object
        (
            [embedHtml] => 
        )

)

Note that the published date I highlighted is NOT the schedule date.

As you can see there is no scheduled date. Do I need to pass more data to 'part'? Their API suggests there's no more data that can be pulled back too.

https://developers.google.com/youtube/v3/docs/search/list#request

Thanks


回答1:


Okay I worked it out.

Simply add liveStreamingDetails to the part parameter.

I was trying to achieve this through search.list. Instead use the videos.list with liveStreamingDetails to get the schedule date as search.list doesn't support liveStreamingDetails.

Cheers




回答2:


The important bit for me was to make sure I have search.list set in my liveStreamingDetails parameter.

Not only that but also make sure event_type is a string, not an integer as it breaks it too.

Hope this helps you



来源:https://stackoverflow.com/questions/35889354/return-upcoming-youtube-api-v3-video-schedule-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!