Using PHP to get Facebook friends statuses? -
that's first post here on so.
i'm using php facebook friends statuses. in particular, i've tried retrieve public statuses 1 of facebook friends, happens first 100 statuses. need statuses , write them in text file. code i'm using, patched many answers read here on so.
$i=0; $result = $facebook->api('/my_friend_id/statuses/', array('access_token' => $facebook->access_token,'limit'=>100,));
//'offset'=>50,used before limit, push limits forward 50, doesn't go beyond //'since'=>2010, read on there field, can't make work.
foreach($result['data'] $post) { echo $i . '<br>'; echo $post['id'] . '<br>'; echo $post['from']['name'] . '<br>'; echo $post['from']['id'] . '<br>'; echo $post['name'] . '<br>'; echo $post['message'] . '<br>'; echo '*---------------------------------------------------*' . '<br>'; $i++; $write_file = fopen("esempio.txt","a"); $message = $post['message'] . '<br>'; fwrite($write_file,$message); fclose($write_file); }
so, clearer, how friends statuses (old , new) in text file?
you need use paging https://developers.facebook.com/docs/reference/api/pagination/
$the_statuses = array(); $your_statuses = $facebook->api("/my_friend_id/statuses/"); while ($your_statuses['data']) { $the_statuses = array_merge( $the_statuses, $your_statuses['data'] ); $paging = $your_statuses['paging']; $next = $paging['next']; $query = parse_url($next, php_url_query); parse_str($query, $par); $your_statuses = $facebook->api( "/my_friend_id/statuses/", 'get', array( 'limit' => $par['limit'], 'until' => $par['until'] )); }
then can loop through statuses
foreach($the_statuses['data'] $post) { echo $i . '<br>'; echo $post['id'] . '<br>'; echo $post['from']['name'] . '<br>'; echo $post['from']['id'] . '<br>'; echo $post['name'] . '<br>'; echo $post['message'] . '<br>'; echo '*---------------------------------------------------*' . '<br>'; $i++; $write_file = fopen("esempio.txt","a"); $message = $post['message'] . '<br>'; fwrite($write_file,$message); fclose($write_file); }
Comments
Post a Comment