I am just starting to dive into the Facebook graph API because I work with a community organization that wants to develop a website that also integrates with Facebook. One of the first things they wanted me to do is obtain some statistics about how many posts/likes/comments they have had, averages per day, types of posts, ect... Since I couldn't find anything pre-built for groups I thought that if I could just download the feed into a database I could write some queries to get the information I need. I found that I can get the information utilizing the feed hook and loop through the pagination but for some reason it doesn't appear to be giving me my entire feed. It only seems to go back a couple months. Any thoughts that may help me here? Here is some sample code.
$url_array=array();
$url = "http://ift.tt/1C9KMrq" . $accessToken;
function recurse_it($url,$c)
{
$feeds=file_get_contents($url);
$feed_data_obj=json_decode($feeds,true);
while(!empty($feed_data_obj['data']))
{
foreach($feed_data_obj['data'] as $item){
$likes = 0;
if(isset($item['likes']['data'])){
$likes = count($item['likes']['data']);
}
$comments = 0;
if(isset($item['comments']['data'])){
$comments = count($item['comments']['data']);
}
$message = '';
if(isset($item['message'])){
$message = str_replace("'","''",$item['message']);
}
$result=pg_query("insert into fbposts(fb_id, fb_id_part1, fb_id_part2, from_id, from_name, to_id, to_name, msg, msg_type, jobs_type, created_time, updated_time, like_count, comment_count)" .
"select '" . $item['id'] . "', " . substr($item['id'],0,strpos($item['id'],'_')) . ", " . substr($item['id'],strpos($item['id'],'_')+1) . ", " . $item['from']['id'] . ", '" . str_replace("'","''",$item['from']['name']) . "', " . $item['to']['data'][0]['id'] . ", '" . str_replace("'","''",$item['to']['data'][0]['name']) . "', '" . $message . "', '" . $item['type'] . "', 'unknown', '" . $item['created_time'] . "', '" . $item['updated_time'] . "', " . $likes . ", " . $comments . ";");
}
$next_url = $feed_data_obj['paging']['next'];
$url_array[$c] = $next_url;
$feeds=file_get_contents($next_url);
$feed_data_obj=json_decode($feeds,true);
$c=$c+1;
}
return $url_array;
}
$final_result=recurse_it($url,0);
Aucun commentaire:
Enregistrer un commentaire