Facebook graph API 'friends' request now only returning 25 friends per page? What's going on? - facebook

My application(game) has been running on Facebook for some time. I start by requesting a friends list via the graph API call: my-uid/friends
asking for user name and profile pic.
Normally I get back a list of all my friends up to a few thousand, until it starts putting friends on to the next page. Which is nice as most of my users get friends in 1 call.
Suddenly however, and with no changes to the app. about 40 minutes ago (18:40 Tuesday (PDT) - 2nd May 2012) I started getting responses with only 25 friends per 'page'!
I can still get my whole friends list using multiple calls, but the game is not currently set up to do that properly. Can anyone tell me why the sudden change? Anyone else seen similar problems and how do I get the list to give me up to 5000 friends per page like it used to.
Reproducible using the Graph API Explorer

I don't know what else to tell you; perhaps the default number returned has changed, but when I try, a call to /me/friends?limit=5000 returns the full list for me (but my friends list is >500 and < 1000 , so maybe it cuts off somewhere along the way)
(Side note: the average number of friends has been found to be ~190 so presumably most users will have less than 500 anyway, and having to page above 500 would be an edge case

In SDK 4.7 you need to pass in a bundle with the number of friends you want to return, I have set it to 5000 as this is the maximum number of friends you can have on Facebook.
You also need to set up your app as a game in the facebook dev console and use invitable friends to get a full friends list
Create your bundle
Bundle bundle = new Bundle();
Add params to your bundle
bundle.putInt("limit", 5000);
Then pass it in to your GraphRequest
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/invitable_friends",
bundle,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//Do something with the response
}
}
).executeAsync();

It seems that facebook changed its limit to 25 results in other api calls too (feed, posts, friends, etc), if you request friends without parameters the JSON response shows the following:
"paging": {
"next": "https://graph.facebook.com/USER_ID/friends?format=json&limit=25&offset=25&__after_id=LAST_ID"
}
Anyway you could/should always set limit & offset parameters to prevent this kind of things, limit = 0 will return all your friends list.
https://graph.facebook.com/USER_ID/friends?limit=0
If you are only requesting friends from a normal user the maximum number allowed is 5,000 so the limit should could be either 0 or 5,000 if you are requesting info from a facebook page or other kind of api calls like posts or feed this limit could increase or decrease.
(Update) Facebook fixed this bug so setting limit to 0 returns 0 friends, you should set a positive limit, thanks Dinuz

I think the best thing you can do is to add limit=5000 parameter as Igy says.
However I posted a bug report since this change wasn't noticed or described in the document.

The number of results returned from the /v2.2/me/friends endpoint now defaults to 25.
Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app.
See Facebook changes
Facebook API change log

If you are using GraphRequest() (e.g. in React Native), you can put it directly in the string field, like so :
new GraphRequest(
'/me',
{
accessToken,
parameters: {
fields: {
string: 'id,email,first_name,last_name,friends.limit(5000)'
}
}
...

Related

Get multiple users from facebook open graph with one call

Calling this URL return a user object with public informations about a facebook user:
https://graph.facebook.com/100000050972893
100000050972893 is the facebook user ID. Is it possible to get multiple user objects with one call? I need to know the gender of about 200 users and I dont think its a good idea calling 200 times the graph URL...
Just found the answer:
https://graph.facebook.com/?ids=100000050972893,100000953354280
But I dont know where the Limit of IDs is you can check with one call...

Facebook get/querying all wall posts (access tokens return completely different values)

I've been trying to query what people have posted on my wall as a quick metric of closeness. I've tried both FQL and the Graph API to make these queries without a problem...
FQL:
SELECT actor_id FROM stream WHERE source_id = me() AND message != "" LIMIT 50
Graph:
FB.api('/me/feed?fields=from&limit=50', function(feedresponse) { //do stuff });
Testing these in the Graph Explorer when the application is set to "Graph API Explorer" returns the values I want - my own and other's posts on my wall.
However when the application is changed to my own application, "Fingerprint", the values include my likes, my recent friendship notifications, etc... information I don't want returned and that completely pollutes the query.
I've still gotten the correct results by passing the Graph API Access Token like so:
var access_token = "CAACEdEose0cBALLruchzIKJ1ewgvcjpPJmo1amJwbMHGYyuk544om8hDILt0ZBXiUAriiNI7VY2g1OOwlEgV4bVyCWZACOf2djD1rYBTIwxBnmseNHUm6qybvus23F4AShctQl3wu0rpPS5ZBh68ypVoDMgyyXEGnu6uXBbzOJ7Tx43m2xHsseo1oiU7A80oelxphhidgZDZD";
FB.api('/me/feed?fields=from&limit=50', { access_token : access_token}, ...
Though it works - it definitely doesn't seem like the right way. Can anyone explain why the results are different and how I can get my feed without the other bullshit FB sends me when I'm using the User Access Token with my App.

Why does my facebook friendlist request doesn't show as many friends as on my profile?

I'm trying to get my users friends lists by using the facebook graph API doing so:
FB.api('me/friends', function(response) {
console.log(response);
user.friends = response;
});
When I test on my own profile I get 95% of my fb friends (583 friends instead of the 602 I can see on my profile). Thus, I see in the response object there is a "next" url for the pagination function which doesn't return anything when triggered. Why is this happening ? Where does that possibly come from ?
Thanks
If you have a problem with next URL for the pagination, try using the offset and limit parameters in the URI.
For example, instead of making an API call to me/friends, make a call to me/friends?limit=100&offset=0. This will start the list of your friends from an offset of 0 and will display a list of 100 friends on on each page. The next URL will work just fine in this case. You can however increase the limit of the users per page.

FB API returning blank for /statuses while result is in /feed

I'm trying to get all the data the logged-in user / one of his friends posted on FB.
I'm currently doing three different calls to:
/<username I want data for>/links
/<username I want data for>/photos/uploaded
/<username I want data for>/statuses
This works just fine for many users. However, some users are returning an empty result ({
"data": [
]
}). When trying to debug I'm noticing that a call to /username/feed is returning results which some of them are links / photos / statuses.
How can this be? Am I calling the wrong endpoints?
This is the relevant API page FB User Object
you are getting data for your account. Please try to reproduce the same on different browser.
(check the same thing on IE)

Facebook Graph API - Finding a users top friends

I am writing a android app that will pull in a list of all the users friends so they can tag them in the photo but displaying a large box of the friends with their photo instead of a list. Because some people have 500+ friends, we all know their are only a handful (maybe 50) that are friends they actively communicate on Facebook by comments or being tagged in photos. I would like to be able to just pull their top xxx friends as it seems Facebook does this same thing on their site, but I just cant find anything in the Graph API to do this task.
Anyone have any pointers?
The other way of doing it is, make a Graph API request for the status messages posted by the user, the friends who have commented or liked his status are the ones with whom he/she interacts the most, doing this is pretty simple, you can use this:
$statuses = $facebook->api('/me/statuses');
foreach($statuses['data'] as $status){
// processing likes array for calculating fanbase.
foreach($status['likes']['data'] as $likesData){
$frid = $likesData['id'];
$frname = $likesData['name'];
$friendArray[$frid] = $frname;
}
foreach($status['comments']['data'] as $comArray){
// processing comments array for calculating fanbase
$frid = $comArray['from']['id'];
$frname = $comArray['from']['name'];
}
}
keep counters as per your choice, and it will be done.
I wanted to do this without requiring additional/extended permissions. I found a fairly decent approximation for my needs was the mutual_friend_count field in the user FQL table.
So I used:
$params = array('method' => 'fql.query',
'query' => 'SELECT uid, pic_square, name
FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
ORDER BY mutual_friend_count DESC
And then just fire that off using the PHP SDK
$friend_array = $facebook->api($params);
I've ran into this same issue in a web app I'm working on, and open-sourced the code I've used, albeit in Ruby:
https://github.com/mikejarema/facebook-friend-rank
This is actually a web service which takes an active access token & user id and (assuming a read_stream permission has been granted) returns a hash of ids to counts which can be used for sorting within your android app.
I suppose since you're running on a smartphone, this let's you offload a series of calls and any call latency to a server somewhere which is running code optimized specifically for the friend ranking task.
In particular, the ranking algorithm looks at a user's 500 most recent interactions (activity feed) and tallies up the frequency of all friends appearing there. The result gives a reasonable ordering of friends, best to worst, and it also works on subsets of friends (eg. sorting mutual friends).
There's lots of room for exploring photo tags, mutual friend counts, and also looking for the type of interactions (eg. a checkin with a friend is probably a better measure of closeness than a like on their status). The project may evolve to encompass some of these considerations.
Here's a sample app using this approach and Friend Rank on the backend, inspect the network calls to see what the API looks like:
http://facebook-friend-rank.herokuapp.com/demo/index.html
If you watch the network traffic from Facebook's iPhone app, you can see they make this FQL call to get the users top 10 friends they communicate most with:
SELECT uid2, communication_rank
FROM friend where uid1 = me()
ORDER BY communication_rank DESC LIMIT 10
Unfortunately this is not available to applications by default. You would need to contact a Facebook engineer to get this field enabled for your application.
I recommend you the following class:
https://github.com/gajus/facebook-friend-rank
It give your friends a score based on user interaction:
'feed_like'
'feed_comment'
'feed_addressed'
'photo_tagged_friend_by_user'
'photo_tagged_user_by_friend'
'photo_like'
'photo_comment'
'friend_mutual'
'inbox_in_conversation'
'inbox_chat'
then it sort the list by score desc.
Hope it helps.
I can think of two direct ways to get a user's "top friends." The first does not require any extended permissions, rather just a valid access token (which as an app owner, you'll have). You make an API call to get the user's feed, which is a connection to the user node.
This call will that user's 25 most recent posts. With any luck, at least some of the items in JSON array returned from this call will be posts from that user's friends. How will know? Well each post comprising the feed, will have an unique id associated with it--whether an Application or FB User is the source of the Post--and each one of those FB ids can be compared against the user's friend list.
The idea of course is that any friends whose posts appear in the last 25 posts of the user's feed, are closer friends than otherwise.
The second technique is to make a call to the Graph API requesting the friendslists connection to the user node. This call requires the *read_friendlists* permission. The name a user gives to a given list is often strongly probative of the importance of the friends comprising that list (e.g., *best_friends*, or whatever); in other words, one or a combination of a couple of those lists will likely give you that user's top friends.