My PHP get YouTube video api function isn't printing anything -
just been crating api (as exercise) latest youtube video , nothing being printed. i'm new php , have started create myself website
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 $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) { } ?>
init.inc.php
<?php $path = dirname(__file__); include("youtube_api.inc.php"); ?>
videos.php
<?php header('content-type: text/plain'); include('init.inc.php'); print_r(get_latestvideo('thegigglesquid')); ?>
this last file supposed print $videos
array.
you never return function.
try adding:
return $videos;
at end of function, outside of if() {} else {}
statement.
function get_latestvideo($username) { $videos = array(); if (true || (time() - filetime("{$globals['path']}/cache/video_cache.txt")) > 3600) { // ... } else { // ... } return $videos; // <-- important! }
Comments
Post a Comment