获取数组中的 Youtube VideoID 详细信息 [英] Get Youtube VideoID details in array

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

问题描述

我已经为此苦苦挣扎了几个小时,但我不知道为什么不起作用.我需要使用 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;
}

我用数组和函数做这件事的原因是因为我想缓存这个函数.

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

我不知道代码有什么问题,我使用完全相同的代码,只是将 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.

推荐答案

我复制了您的代码并运行了它.现在 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.

以下是一些对我来说非常适合的修改后的代码:

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 VideoID 详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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