Get Youtube VideoID data in an array

I struggled with this for several hours and I have no idea why it is not working. I need to get information from VideoID using the YouTube and Zend APIs, so I created a function like

function listYoutubeVideo($id) { $videos = array(); try { $yt = new Zend_Gdata_YouTube(); $videoFeed = $yt->getVideoEntry($id); foreach ($videoFeed as $videoEntry) { $videoThumbnails = $videoEntry->getVideoThumbnails(); $videos[] = array( 'thumbnail' => $videoThumbnails[0]['url'], 'title' => $videoEntry->getVideoTitle(), 'description' => $videoEntry->getVideoDescription(), 'tags' => implode(', ', $videoEntry->getVideoTags()), 'url' => $videoEntry->getVideoWatchPageUrl(), 'flash' => $videoEntry->getFlashPlayerUrl(), 'dura' => $videoEntry->getVideoDuration(), 'id' => $videoEntry->getVideoId() ); } } catch (Exception $e) { } return $videos; } 

The reason I am doing this with an array and a function is because I want to cache this function.

I have no idea what is wrong with the code, I use exactly the same, just changing getVideoEntry for other types of feeds, and it works.

+4
source share
2 answers

I duplicated your code and ran it. Now getVideoEntry seems to return individual video data, but for some reason do you expect this to be a collection? In addition, if you cache, you can create some kind of check for empty data return.

Here is some reworked code that worked fine for me:

 function listYoutubeVideo($id) { $video = array(); try { $yt = new Zend_Gdata_YouTube(); $videoEntry = $yt->getVideoEntry($id); $videoThumbnails = $videoEntry->getVideoThumbnails(); $video = array( 'thumbnail' => $videoThumbnails[0]['url'], 'title' => $videoEntry->getVideoTitle(), 'description' => $videoEntry->getVideoDescription(), 'tags' => implode(', ', $videoEntry->getVideoTags()), 'url' => $videoEntry->getVideoWatchPageUrl(), 'flash' => $videoEntry->getFlashPlayerUrl(), 'dura' => $videoEntry->getVideoDuration(), 'id' => $videoEntry->getVideoId() ); } catch (Exception $e) { /* echo $e->getMessage(); exit(); */ } return $video; } 
+3
source

This is a bug in the Zend structure:

http://framework.zend.com/issues/browse/ZF-12461?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabs

For a quick fix, you can edit Zend / Gdata / YouTube / VideoEntry.php

line 587:

 // $videoId = substr($fullId, $position + 1); $url = $this->getFlashPlayerUrl(); $videoId = substr($url, 25, 11); 

This is not a fantasy, but it does its job.

+4
source

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


All Articles