Facebook GraphAPI Waterfall!
ANDREW I DONT CARE ABOUT YOUR STORIES! JUST GIVE ME THE LINK! >> /facefall/
So its been a long weekend, but i had a lot of time to myself this weekend, and decided to play a bit with some of the side projects i’ve been interested in.
With regards to the previous posts, the code has been updated and fixed, ill update the post a little later – but hopefully we (@Paterva) will be releasing the transforms to the public this week so everyone can play!
One of the first ones i wanted to tackle was faceFall – essentially twitterfall for the facebook graphAPI, so you can quickly search for a topic and watch the status messages / links fall down as they arrive :)
So check it out: /facefall/ ( yes i realise the UI looks like ass, but i cant get a nice design to work… if you have one or want to build one, PLEASE let me know!)
Some stuff id need to fix:
- Removing doesn't work well ( probably my lame ass jscript )
- Doesnt do any correlation (like same person featured on x Topics)
- Needs more info -- only does status/links atm
I also cleaned the whiteboard:
Technical Info after the break!
So accessing the facebook graphAPI search is trivial, you simply browse to https://graph.facebook.com/search?q=<yourterm>&type=post , and you will get out some simply json like so:
"data": [
{
"id": "100000065889023_127068694016086",
"from": {
"name": "Joe Mitchell",
"id": "100000065889023"
},
"message": "had a wicked time fishing over the waterfront with Andrew Young, Owain Cadman and caught six gobby's",
"type": "status",
"created_time": "2010-11-07T19:16:13+0000",
"updated_time": "2010-11-07T19:16:13+0000"
},
{
"id": "1393843973_170920819601364",
"from": {
"name": "Tabi Harvey",
"id": "1393843973"
},
"message": "Andrew is now a week old and is doing great he is a little fighter like tristan was thank god for that and hope he gets better everyday",
"type": "status",
"created_time": "2010-11-07T19:16:13+0000",
"updated_time": "2010-11-07T19:16:13+0000",
"attribution": "Mobile Web"
}
],
"paging": {
"previous": "https://graph.facebook.com/search?q=andrew&type=post&limit=25&since=2010-11-07T19%3A16%3A13%2B0000",
"next": "https://graph.facebook.com/search?q=andrew&type=post&limit=25&until=2010-11-07T19%3A11%3A57%2B0000"
}
}
So its really just a matter of piecing together the code with some php like so:
-1 && $term)
{
$url = "https://graph.facebook.com/search?q=\"" . urlencode($term) . "\"&type=post";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_URL, $url);
$returned = curl_exec($ch);
$returned = json_decode($returned,TRUE);
curl_close ($ch);
$posts = $returned["data"];
$facefallResults = array();
if(is_array($posts))
{
foreach($posts as $p)
{
$userDetails = $p["from"];
if(in_array($p["type"],array("status","link")))
{
if($p["type"] == "status")
{
$msg = $p["message"];
}
if($p["type"] == "link")
{
if(isset($p["message"]))
{
$msg = $p["message"];
}
else
{
$msg = "" . $p["link"] . "";
}
}
$finalMsg = $msg;
if(strlen($finalMsg) > 100)
{
$msg = substr($finalMsg,0,100) . "...";
}
$currentDate = date('Y-m-d h:i:s', strtotime($p["created_time"]));
$lastDate = date('Y-m-d h:i:s', strtotime($lastID));
if($currentDate > $lastDate)
{
$facefallResults[] = array("id"=>$p["created_time"],"message"=>$finalMsg,"UID" => $userDetails["id"], "Name" => $userDetails["name"], "Pic"=>"http://graph.facebook.com/" . $userDetails["id"] . "/picture","phrase"=>$term,"createdtime"=>$currentDate,"fullMSG"=>$msg);
}
}
}
}
$facefallResults = array_reverse($facefallResults);
echo json_encode($facefallResults);
}
?>
And throwing in some ajax :)
Let me know if anyone wants to ask anything on it and so on :) I think i’ll build a quick RSS feed for this later on, its probably about 30 mins of work from here, perhaps even tonight still :)
Cheers, Andrew