如何按照上传日期顺序获取YouTube视频

时间:2014-01-11 15:39:44

标签: php youtube

我有一个系统可以从YouTube频道获取大量视频,例如:

                <?php
                    $feedURL = 'https://gdata.youtube.com/feeds/api/videos?author=UCMlW2qG20hcFYo06rcit4CQ&max-results=48&order=date';

                    $sxml = simplexml_load_file($feedURL);

                    $i = 0;
                    foreach ($sxml->entry as $entry) {
                        $i++;

                        $media = $entry->children('http://search.yahoo.com/mrss/');

                        $attrs = $media->group->player->attributes();
                        $watch = $attrs['url'];
                        $vars;
                        parse_str( parse_url( $watch, PHP_URL_QUERY ), $vars );
                        $id = $vars['v'];

                        $check = $i % 3;

                        if($check == 1) {
                ?>
                        <div class="video-col tri-col-1 empty">
                            <img src="http://img.youtube.com/vi/<?php echo $id ?>/mqdefault.jpg" data-id="<?php echo $id ?>" class="video" />
                        </div>
                <?php
                        } else if($check == 2) {
                ?>
                        <div class="video-col tri-col-2 empty">
                            <img src="http://img.youtube.com/vi/<?php echo $id ?>/mqdefault.jpg" data-id="<?php echo $id ?>" class="video" />
                        </div>
                <?php
                        } else {
                ?>
                        <div class="video-col tri-col-3 empty">
                            <img src="http://img.youtube.com/vi/<?php echo $id ?>/mqdefault.jpg" data-id="<?php echo $id ?>" class="video" />
                        </div>
                <?php
                        }

                    }
                ?>

但是,当我在网址中添加“&amp; order = date”标记时,视频不按时间顺序提供。我如何更改代码以确保视频按时间顺序提供?

1 个答案:

答案 0 :(得分:0)

因为参数是orderby,而不是order

https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters#orderbysp

  

视频供稿和播放列表供稿支持的orderby参数指定将用于在API响应中对订单进行排序的方法