Work: I am a health information technology architect, management consultant, and Adjunct Professor located in the Washington, DC Area.
Play: Red Sox and Patriots fan, dog owner, technologist, coffee addict
View my Online Profile / Resume
Loading Tweet...
1 post tagged facebook

I am in the process of adding another source of data to my Semantic Web Dashboard. I want to chart my number of friends via Social Media over time. I started with Facebook - but Facebook doesn’t give me access to my historical friends count, only the current count today. So, I’m writing a app that will record the number of friends I have on a daily basis. I plan to expand it down the road to include number of postings and other things. This will mean that any chart I create will have limited data initially. I didn’t get to actually creating the chart yet, it took me long enough to figure out Facebook’s Graph API and to get that working properly (did I mention that I hate JSON?).
Here is the source to my PHP script that grabs my friend count:
<?php
//require_once(“facebook-php-sdk-master/src/facebook.php”);
$user_id = “7412441”;
$app_id = “REMOVED”;
$app_secret = “REMOVED”;
$my_url = “REMOVED”;
$app_token_url = “https://graph.facebook.com/oauth/access_token?”
. “client_id=” . $app_id
. “&client_secret=” . $app_secret
. “&grant_type=client_credentials”;
$response = file_get_contents($app_token_url);
$params = null;
parse_str($response, $params);
$graph_url = “https://graph.facebook.com/app?access_token=”
. $params[‘access_token’];
//$app_details = json_decode(file_get_contents($graph_url), true);
//$query_url = “https://graph.facebook.com//fql?q=SELECT+friend_count+FROM+user+WHERE+uid=” . $user_id . “&access_token=” . $params[‘access_token’];
$query_url = “https://graph.facebook.com/$user_id?fields=friends&access_token=” . $params[‘access_token’];
$rawdata = file_get_contents($query_url);
//echo $rawdata;
$friends = json_decode($rawdata, true);
$friends_count = count($friends[‘friends’][‘data’]);
echo $friends_count;
// Write to RDF, not complete yet.
$RDFData = “data.ttl”;
$fh = fopen($RDFData, ‘a’);
$stringData = “”;
?>
Loading posts...