en: Negocio
YouTube ofrece acceso libre a sus vídeos a través de una interfaz API abierta y canales RSS.
Gracias a esta API, podrás integrar fácilmente en tu aplicación vídeos online procedentes del mayor repositorio de vídeos de Internet.
Para ello únicamente deberás de crearte un perfil de desarrollador.
Una vez tenemos creado nuestro perfil de desarrollador se nos ofrece un ID de desarrollador con el que podremos utilizar la API, una vez la tengas mediante una llamada a esta url podrás comprobar si tu cuenta está activa.
http://www.youtube.com/api2_rest?method=youtube.users.get_profile&dev_id=ID_DESAROLLADOR&user=USUARIO_YOUTUBE
Tenemos dos posibilidades a la hora de utilizar los servicios de la API, podemos recoger información de usuarios o de vídeos.
Ejemplo de uso de la api de YouTube
Descargar archivos: clase + ejemplo
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(“/\array_shift($url);
array_shift($thumb_nail);
array_shift($description);
array_shift($video);for($i=0;$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 "“; }
}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_id=$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);
}
}
?>
<?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>
Ver ejemplo de uso de la api de YouTube
Por último tenemos que destacar que Google prepara una nueva API para YouTube que ampliará enormemente estas funcionalidades pero aún no esta preparada.
Esta nueva API estará basada en el estándar Google Data (GData).
Según el YouTube Developer Blog, el nuevo GData API sustituirá finalmente el YouTube API y proporcionará más escalabilidad, mejor integración con las GData APIs, bibliotecas y recursos de desarrollo existentes.