Skip to content

Instantly share code, notes, and snippets.

@timwco
Created February 16, 2011 20:43
Show Gist options
  • Save timwco/830155 to your computer and use it in GitHub Desktop.
Save timwco/830155 to your computer and use it in GitHub Desktop.
Facebook XML - Like Pull
$xml_string = 'http://domain.com/sitemap.xml';
//load the xml string using simplexml
$xml = simplexml_load_file($xml_string);
//loop through the each node of user
$results = array();
foreach($xml->url as $url){
$link = $url->loc;
$facebook = 'http://api.facebook.com/method/fql.query?query=';
$encode = urlencode("select total_count from link_stat where url =\"$link\"");
$fburl = $facebook . $encode;
// Run cURL
$ch = curl_init($fburl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$cres = curl_exec($ch);
curl_close($ch);
$dres = new DomDocument();
$dres->loadXML($cres);
$fres = $dres->getElementsByTagName('total_count');
$lval = (int)$fres->item(0)->nodeValue;
echo "<p>URL: $link - Likes: $lval </p>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment