4

我已经为此苦苦挣扎了几个小时,我不知道为什么不工作。我需要使用 YouTube API 和 Zend 从 VideoID 获取详细信息,所以我创建了一个这样的函数

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;
}

我用数组和函数做它的原因是因为我想缓存函数。

我不知道代码有什么问题,我使用完全相同的代码,只是将 getVideoEntry 更改为其他类型的提要,它可以工作。

4

2 回答 2

4

This is a bug in Zend framework:

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

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

line 587:

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

It's not fancy but gets the job done.

于 2012-11-07T09:06:41.550 回答
3

我复制了你的代码并运行了它。现在 getVideoEntry 似乎正在返回单个视频的数据,但出于某种原因,您希望它是一个集合?此外,如果您缓存,您可能希望创建一些空数据返回检查。

这是一些对我来说非常有用的修改代码:

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;
}
于 2011-06-30T08:36:50.573 回答