Skip to content

Instantly share code, notes, and snippets.

@carlok
Created December 11, 2012 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlok/4257253 to your computer and use it in GitHub Desktop.
Save carlok/4257253 to your computer and use it in GitHub Desktop.
Simple snippet to get the YouTube pages of the commenters of a video
<?php
// Carlo Perassi, 2012: snippet
// Simple snippet to get the YouTube pages of the commenters of a video
$youtube = new stdClass();
$youtube->base = 'https://gdata.youtube.com/feeds/api/videos/';
$youtube->user = 'https://gdata.youtube.com/feeds/api/users/';
$youtube->id = $_GET['id']; // ID of the video, just for testing
// FIXME @s
if ($stream_base = fopen($youtube->base . $youtube->id . '/comments', 'r')) {
$xml_base = new SimpleXMLElement(@stream_get_contents($stream_base));
echo "<ul>\n";
foreach ($xml_base->entry as $entry) {
list($before, $after) = explode("https://", $entry->author->uri);
$mtoken = explode("/", $after);
if ($stream_user = fopen($youtube->user . $mtoken[4], 'r')) {
$xml_user = new SimpleXMLElement(@stream_get_contents($stream_user));
foreach ($xml_user->link as $link) {
if ($link['rel'] == 'alternate') {
echo '<li><a href="' . $link['href'] . '">' . $link['href'] . "</a></li>\n";
}
}
}
}
echo "</ul>\n";
fclose($stream_base);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment