获取阵​​列的Youtube视频ID的详细信息 [英] Get Youtube VideoID details in array

查看:168
本文介绍了获取阵​​列的Youtube视频ID的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在挣扎与这几个小时,我不知道为什么不工作。
我需要使用YouTube API和Zend从VideoID的细节,所以我创造了这样的功能。

I've been struggling with this for hours and i have no idea why is not working. I need to get Details from a VideoID using YouTube API and Zend, so i created a function like this

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

原因IM与阵列和一个函数这样做是因为我想缓存功能。

The reason im doing it with an array and a function is because i wanna cache the function.

我不知道什么是错的code,我使用完全相同一只是改变getVideoEntry其他类型的饲料相同,​​它的工作原理。

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

推荐答案

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

I duplicated your code and ran it. Now getVideoEntry seems to be returning a single video's data, but for some reason you expect it to be a collection? Also if you cache, you might want to create some check for an empty data return.

下面是一些修改code完美地为我工作:

Here is some revised code that worked perfectly 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;
}

这篇关于获取阵​​列的Youtube视频ID的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆