开发者

Zend Gdata Library

hi i am useing zend Gdata Library for youtube videos i am trying to show more then 20 v开发者_JAVA技巧ideos or i can set how much videos i want to show but i found no options

  $yt = new Zend_Gdata_YouTube();
  $videoFeed = $yt->getUserFavorites('liz');

is there a way to get more then 20 videos or less Zend Gdata default is 20

you can view here

http://framework.zend.com/manual/en/zend.gdata.youtube.html


After some more research I think I found some solution. Check there http://code.google.com/apis/youtube/2.0/developers_guide_php.html#Pagination You should write recursive function loop trough video feed pages. For my app it was something like this (method in class):

<?php
 //...
 protected function build_favs_html($videos) {

 //just saving html here. Mind the .= operator.
 // I think you'll be doing this in some other way
 $this->_html_response .= View::factory('videos')
                ->set('videos', $videos)
                ->set('type', 'load_favs');

// See whether we have another set of results
 try {
  $videos = $videos->getNextFeed();
  }
 catch (Zend_Gdata_App_Exception $e) {
  //break function execution if there are no more result sets
  return null;
  }

  //if there are result sets we continue calling same function on and on
  $this->build_favs_html($videos);
 }


I'm not sure if this can be done when requesting user favorites, as I've never used that feature, but when requesting videos via search terms you can set the results number via the setMaxResults method. You might be able to work this in with your user favorites request.

Here's a snippet of code we use:

    $yt = new Zend_Gdata_YouTube();
    $yt->setMajorProtocolVersion(2);
    $query = $yt->newVideoQuery();
    $query->setOrderBy('viewCount');
    $query->setSafeSearch('strict');
    $query->setFormat($searchFormat);
    $query->setVideoQuery($searchTerms);
    $query->setMaxResults($limit); // number of returned results set here
    $query->setStartIndex($offset);
    $results = $yt->getVideoFeed($query->getQueryUrl(2));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜