Fetch 3 Latest YouTube Channel Video

Using the Youtube API , I created a class for my needs. (It works with Zend FW)

class youtube extends html { var $yt, $user; public function __construct($user) { require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata_YouTube'); $this->yt = new Zend_Gdata_YouTube(); $this->yt->setMajorProtocolVersion(2); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); $this->yt->getHttpClient()->setConfig(array('timeout' => 180)); $this->user = $user; } 

}

The problem is that when I use

 $this->yt->getuserUploads($this->user) 

for other class methods, it gets ALL videos. I want to get the last 3 videos from $user . How to do it?

+4
source share
2 answers

I have a very short time at the moment, otherwise I would try using your code. This can help if you cannot handle it or if no one comes back with an answer using your code.

I put together a quick and dirty solution as an answer for those who wanted to show a thumbnail corresponding to the last video uploaded to Youtube by a specific user - I encoded a simple controller action and presentation that would display a thumbnail of the video that was a link to the video.

An example can be easily customized to show a certain number of videos by changing

 if($i==1) break; 

however, there are probably more elegant ways to do this than what I did, as I say it was quick and dirty to answer the question.

I used the Zend_Feed_Reader class instead of the Zend_Gdata_YouTube class. In the short term, this may help.

Good luck, let me know if this helped.

All the best, Dave: -D

Link to a question with my example

0
source

Take a look at:

 $query = $yt->newVideoQuery(); $query->maxResults = 3; $query->orderBy = 'published'; $query->author = 'ThisIsHorosho'; $query->startIndex = 1; $videoFeed = $yt->getUserUploads(null,$query); foreach($videoFeed as $videoEntry) { echo $videoEntry->getVideoWatchPageUrl() . PHP_EOL; } 
0
source

Source: https://habr.com/ru/post/1403332/


All Articles