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

これはZendフレームワークのバグです。

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

迅速な修正のために、Zend / Gdata / YouTube/VideoEntry.phpを編集できます

587行目:

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

それは派手ではありませんが、仕事を成し遂げます。

于 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 に答える