Facebook Graph API gets all users and their status

I am using the Facebook Graph API, and I was wondering, is there anyway to get a list of all users and their current status in one call?

I basically need the same results as https://graph.facebook.com/me/friends , but with the current status included in each object.

Thanks for any help!

EDIT:

Here are some explanations. if https://graph.facebook.com/me/friends?access_token=... gets me this: (AKA is a list of all my friends)

 { "data": [ { "name": "Foo", "id": "1" }, { "name": "Bar", "id": "2" }, { "name": "Foo Bar", "id": "3" }, { "name": "Bar Foo", "id": "4" } ] } 

which URL or FQL will get me: (AKA - a list of all my friends and their statuses)

 { "data": [ { "name": "Foo", "id": "1" "status": "This is my current status!" }, { "name": "Bar", "id": "2" "status": "This is my current status!" }, { "name": "Foo Bar", "id": "3" "status": "This is my current status!" }, { "name": "Bar Foo", "id": "4" "status": "This is my current status!" } ] } 

I only want to make one call, because, unlike me, most people have more than 100 friends, and I do not want to make 100+ calls just to receive statuses.

+8
json facebook facebook-graph-api
source share
4 answers

While the new Batch API should do what you ask for, I could not get it to work correctly. It seems that it is still buggy.

Now, to achieve this with fql.multiquery , here is a brief example:

 <?php $app_id = "APP_ID"; $app_secret = "APP_SECRET"; $my_url = "REDIRECT_URL"; $code = $_REQUEST["code"]; if(empty($code)) { $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url); echo("<script> top.location.href='" . $dialog_url . "'</script>"); } $token_url = "https://graph.facebook.com/oauth/access_token?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code; $access_token = file_get_contents($token_url); $queries = '{"query1":"SELECT uid,name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1=me())","query2":"SELECT uid,message FROM status WHERE uid IN (SELECT uid FROM #query1)"}'; $multiquery = "https://api.facebook.com/method/fql.multiquery?queries=" . urlencode($queries) . "&format=json&" . $access_token; $res = json_decode(file_get_contents($multiquery), TRUE); $final = array(); foreach( $res[1]['fql_result_set'] as $i=>$message_arr ) { foreach( $res[0]['fql_result_set'] as $j=>$friend ) { if( $message_arr['uid'] == $friend['uid'] ) { $friend['message'] = $message_arr['message']; $final[] = $friend; break; } } } print_r($final); ?> 

Here we get the user ID and name in the first request and receive status messages from the second.
Now this will return fewer results in the first query or second! because:

  • A friend may not have sent a status message for the last 30 days , so it will not appear in the second request (the second has fewer results).
  • A friend may have posted more than one status message in the last 30 days (should he return all of them - up to 50? !!) I'm not sure, but if so, then the second will / should return more results than the first. Therefore, I only get one message (note the break ).
+8
source share

Try the following fql:

 Select uid, message from status where uid in (select uid2 from friends where uid1 = [active user id]) 

Just set a limit on a specific date, because by default the last 50 updates / or the last 30 days of activity will be returned.

+3
source share

hi you just need to get the extended permission user_status or friend_status for this, and any call to me on the object will capture the current status of the user ..

 json_decode (file_get_contents ('https://graph.facebook.com/me/friends?access_token='.$cookie [' access_token ']));
0
source share

Thanks to @mgilson for his answer, this can be combined into a single FQL statement as follows:

SELECT status_id, uid, message FROM status WHERE uid IN (SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me ()))

The magic I found requests permission from friends_status , which will open from public messages to friends and others that will help reproduce the feeling of the wall.

0
source share

All Articles