微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

zend-framework – Youtube API – 如何限制分页结果?

我想抓住用户上传(即:BBC)并将输出限制为每页10个.

虽然我可以使用以下URL:
http://gdata.youtube.com/feeds/api/users/bbc/uploads/?start-index=1&max-results=10

以上工作没问题.

我想使用查询方法

Zend框架文档:
http://framework.zend.com/manual/en/zend.gdata.youtube.html

说明我可以检索用户上传的视频,但理想情况下我想使用查询方法来限制分页的结果.

查询方法在Zend框架文档上(与之前在“按元数据搜索视频”标题下的页面相同),与此类似:


$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->setTime('today');
$query->setMaxResults(10);
$videoFeed = $yt->getUserUploads( NULL,$query );

print’< ol>‘;
foreach($videoFeed as $video):
打印’< li>‘ . $video->标题. ‘< /立GT;’;
endforeach;
print’< / ol>‘;

问题是我不能做$query-> setUser(‘bbc’).

我尝试了setAuthor,但这会返回一个完全不同的结果.

理想情况下,我想使用查询方法分页方式获取结果.

如何使用$query方法设置分页限制?

谢谢.

我基本上以与worchyld相同的方式解决了这个问题:
$username = 'ignite';
    $limit = 30;  // Youtube will throw an exception if > 50
    $offset = 1;  // First video is 1 (silly non-programmers!)
    $videoFeed = null;
    $uploadCount = 0;
    try {
        $yt = new Zend_Gdata_YouTube();
        $yt->setMajorProtocolVersion(2);
        $userProfile = $yt->getUserProfile($username);
        $uploadCount = $userProfile->getFeedLink('http://gdata.youtube.com/schemas/2007#user.uploads')->countHint;

        // The following code is a dirty hack to get pagination with the YouTube API without always starting from the first result
        // The following code snippet was copied from Zend_Gdata_YouTube->getUserUploads();
        $url = Zend_Gdata_YouTube::USER_URI .'/'. $username .'/'. Zend_Gdata_YouTube::UPLOADS_URI_SUFFIX;
        $location = new Zend_Gdata_YouTube_VideoQuery($url);
        $location->setStartIndex($offset);
        $location->setMaxResults($limit);
        $videoFeed = $yt->getVideoFeed($location);
    } catch (Exception $e) {
        // Exception handling goes here!
        return;
    }

Zend YouTube API似乎很愚蠢,因为包含的getUserUploads方法在实际获取Feed之前从不返回VideoQuery实例,虽然您可以将位置对象作为第二个参数传递,但它只是“或者 – ”情况 – 它只会使用用户名参数构造一个基本的uri或只使用位置,你必须自己构建整个东西(如上所述).

原文地址:https://www.jb51.cc/php/130328.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐