My PHP get YouTube视频api函数不是';不要打印任何东西

My PHP get YouTube视频api函数不是';不要打印任何东西,php,api,youtube,Php,Api,Youtube,我刚刚制作了一个API(作为练习)来获取我最新的YouTube视频,但没有打印任何内容。我对PHP非常陌生,刚刚开始创建自己的网站 youtube_api.inc.php <?php function get_latestvideo($username) { if (true || (time() - filetime("{$GLOBALS['path']}/cache/video_cache.txt")) > 3600) { $videos

我刚刚制作了一个API(作为练习)来获取我最新的YouTube视频,但没有打印任何内容。我对PHP非常陌生,刚刚开始创建自己的网站

youtube_api.inc.php

    <?php

function get_latestvideo($username)
{
    if (true || (time() - filetime("{$GLOBALS['path']}/cache/video_cache.txt")) > 3600)
    {
        $videos = array();

        $data = "http://gdata.youtube.com/feeds/api/users/{$username}/uploads?start-index=1&max-results=1&v=2&alt=json";
        foreach (json_decode(file_get_contents("$data"))->feed->entry as $video)
        {
            $url = (array)$video->link[0];

            $videos[] = array(
                'title' => $video->title->{'$t'},
                'desc' => $video->{'media$group'}->{'media$description'}->{'$t'},
                'url' => $url['href'],
            );
        }

        file_put_contents("{$GLOBALS['path']}/cache/video_cache.txt", serialize($videos));
    }else{
        $videos = unserialize(file_get_contents("{$GLOBALS['path']}/cache/video_cache.txt"));
    }
}

function get_playlists($username)
{

}

?>

您永远不会从函数返回任何内容

尝试添加:

return $videos;
在函数末尾,在
if(){}else{}
语句之外

function get_latestvideo($username) {    
    $videos = array();
    if (true || (time() - filetime("{$GLOBALS['path']}/cache/video_cache.txt")) > 3600) {
        // ...
    } else {
        // ...
    }
    return $videos; // <-- Important!
}
函数获取最新视频($username){
$videos=array();
if(true | |(time()-filetime({$GLOBALS['path']}/cache/video_cache.txt”)>3600){
// ...
}否则{
// ...
}

return$videos;//Ahhh,是的,已经整理好了。谢谢,你为这么一个不起眼的小解决方案提供了巨大的帮助:D
return $videos;
function get_latestvideo($username) {    
    $videos = array();
    if (true || (time() - filetime("{$GLOBALS['path']}/cache/video_cache.txt")) > 3600) {
        // ...
    } else {
        // ...
    }
    return $videos; // <-- Important!
}