J'avais raison de penser que j'aurais dû appeler l'URL intégrée. Pour ce faire, j'ai dû extraire l'identifiant vidéo et le brancher sur l'URL d'intégration pour chaque entrée. Si quelqu'un cherche à faire quelque chose de similaire, voici le code de travail (le lien ci-dessus ne fonctionnera plus - il ne servait qu'à tester):
<?php
//Credits: Mixed some code from Vikram Vaswani (http://www.ibm.com/developerworks/xml/library/x-youtubeapi/), Matt (http://stackoverflow.com/questions/7221485/get-youtube-video-id-from-url-w-php), & Tim (http://groups.google.com/group/youtube-api-gdata/browse_thread/thread/fc1efc399f9cc4c/d1a48cf5d4389cf8?lnk=gst&q=colorbox#d1a48cf5d4389cf8), and then messed around with it to fit my needs.
function getYoutubeId($ytURL)
{
$urlData = parse_url($ytURL);
//echo '<br>'.$urlData["host"].'<br>';
if($urlData["host"] == 'www.youtube.com') // Check for valid youtube url
{
$query_str = parse_url($ytURL , PHP_URL_QUERY);
parse_str($query_str, $args);
$ytvID = $args['v'];
return $ytvID;
}
else
{
//echo 'This is not a valid youtube video url. Please, give a valid url...';
return 0;
}
}
// set feed URL
$feedURL = 'your feed url here';
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
?>
<h1 class="page-title">Video Gallery</h1>
<?php
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
//get video id
$videoid = $yt->videoid[0];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
$videoId = getYoutubeId($watch);
?>
<div class="item">
<h1 class="video-title">
<a class="youtube" href="http://www.youtube.com/embed/<?php echo $videoId ?>?rel=0&wmode=transparent"><?php echo $media->group->title; ?></a>
</h1>
<p>
<span class="video-thumbnail">
<a class="youtube" href="http://www.youtube.com/embed/<?php echo $videoId ?>?rel=0&wmode=transparent" title="<?php echo $media->group->title; ?>"><img src="<?php echo $thumbnail;?>" /></a>
<br/>click to view
</span>
</p>
</div>
<?php
}
?>
Des idées? Je n'ai toujours pas été en mesure d'identifier le problème, et encore moins de trouver une solution. Peut-être que je devrais appeler le lien YouTube d'une manière différente pour que cela fonctionne? – JCM
Je pense que j'ai peut-être trouvé le problème. Je tire l'URL "youtube.com/watch", mais je pense que je devrais tirer l'URL "youtube.com/embed". Si quelqu'un a un aperçu sur la façon de le faire, s'il vous plaît partager. Sinon, je continuerai à chercher. – JCM