Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/06/2011, 01:51
SergioL29
 
Fecha de Ingreso: mayo-2011
Ubicación: Granada
Mensajes: 20
Antigüedad: 13 años
Puntos: 0
Exclamación Problema de errores con clase PHP para Youtube

Estado informandome sobre que YouTube ha abierto sus bases de datos. Os comento que necesito hacer.
Tengo mi web y un canal de youtube y quiero mostrar los videos de mi canal e informacion de ellos en mi web.
Estado informandome y existen clases de PHP que automaticamente dandole el ID de desarrollador te muestra los videos. Pero ninguna me funciona
Os dejo la informacion que encontre sobre las clases a ver si entre todos conseguimos que funcione
Un saludo,

Clase
Cita:
<?php
class youTube
{
function get_feed($feed)
{
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $feed);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$xml = curl_exec($ch);
curl_close($ch);

return $xml;
}

function yt_results($xml, $howmany)
{
preg_match_all("/\(.+?)\<\/url\>/smi",$xml, $url);
preg_match_all("/\(.+?)\<\/description\>/smi",$xml, $description);
preg_match_all("/\(.+?)\<\/video\>/smi",$xml, $video);
preg_match_all("/\ (.+?)\<\/thumbnail_url\>/smi",$xml, $thumb_nail);

array_shift($url);
array_shift($thumb_nail);
array_shift($description);
array_shift($video);

for($i=0;$i;$i++)
{
$description[0][$i] = preg_replace("/</","<",$description[0][$i]);
$description[0][$i] = html_entity_decode($description[0][$i],ENT_QUOTES);
}

$total_videos = count($video[0]);

if($howmany > $total_videos)
{
$howmany = $total_videos;
}

if(!$howmany || $howmany == 0)
{
$howmany = $total_videos;
}

for($i = 0; $i<$howmany; $i++)
{
print "
"."
Descripcion: ".$description[0][$i]."

"; }
}

function yt_featured($dev_id, $howmany)
{
$feed = "http://www.youtube.com/api2_rest?method=youtube.videos.list_featured&dev_ id=$dev_id";
$xml = $this->get_feed($feed);
$this->yt_results($xml, $howmany);
}

function yt_user($dev_id, $user, $howmany)
{
$feed = "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_user&dev_i d=$dev_id&user=$user";
$xml = $this->get_feed($feed);
$this->yt_results($xml, $howmany);
}

function yt_tag($dev_id, $tag, $howmany)
{
$feed = "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id =$dev_id&tag=$tag";
$xml = $this->get_feed($feed);
$this->yt_results($xml, $howmany);
}
}
?>
?>
Index
Cita:
<?php
require_once(‘class.youtube.php’);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Clase para la API de YouTube</title>
</head>
<body>
<?php
$yt = new youTube;
print "<p>Videos: </p>";
$yt->yt_featured("ID_DESARROLLADOR", 3);
print "<p>Videos de usuarios: </p>";
$yt->yt_user("ID_DESARROLLADOR", "taylorrobinson", 3);
print "<p>Videos por etiquetas: </p>";
$yt->yt_tag("ID_DESARROLLADOR", "futbol", 3);
?>
</body>
</html>
Informacion obtenida del siguiente enlace:
http://www.tufuncion.com/api-youtube

Que errores ven que puedan existir?