I am trying to retrieve a list of a user's Facebook friends by using the code
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.id);
}
}];
But whenever I use that code it just returns Found: 0 friends. I'm putting it inside the Viewcontroller to execute after the user logs in through Facebook. I already requested user_friends permissions and I have a friend who is signed up on the app. If it makes any difference the app is also using Quickblox SDK so if there's any way to do it with that that'd be great!
use this code
FBRequest *friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary *result ,NSError *error){
NSLog(#"Friend data :%#",result);
NSArray *friends = [result objectForKey:#"data"];
NSLog(#"friends :%#",friends);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#",friend.name,friend.id);
}
}];
Have a look at Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app
This is by design and has been discussed dozens of times here.
Related
i am using this code for getting Facebook friend list in iOS sdk 8.1.
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %lu friends", (unsigned long)friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.objectID);
}
}];
but it returns null value.
Since Graph API v2.0, the /{user_id}/friends endpoint does only return those friends who also gave your app the respective permission.
See
https://developers.facebook.com/docs/apps/changelog#v2_0
The /me/friends endpoint no longer includes the full list of a person's friends. Instead, it now returns the list of that person's friends who are also using your app.
I am trying to fetch facebook friend list of the user but it returning only count of the friends.Bellow is my code .Is there anything wrong in this code?
-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#"me/friends result=%#",result);
NSLog(#"me/friends error = %#", error.description);
NSArray *friendList = [result objectForKey:#"data"];
//[m_allFriends addObjectsFromArray: friendList];
}];
}
When you registered your app to facebook. Facebook provide only three permission , these permission is by default approved
user_friends Provides access to a person's list of friends that also use your app. This permission is approved by default.
according to this you can get only those friend who use your app.
check this link
https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends
how can i get the Facebook all friend list in my iOS Application tableview and also i want to write some text on the particular friend
I'm using Facebook latest sdk
code :
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id<FBGraphUser> result, NSError *error) {
/* handle the result */
NSLog(#"%#", result);
}];
With Facebook SDK 3.0 you can do this:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"I have a friend named %# with id %#", friend.name, friend.id);
}
}];
Hope this helps..
I try to login user to my app with the following permissions:
NSArray* permissions = [[NSArray alloc] initWithObjects:#"email", #"read_friendlists", #"user_friends", nil];
After login I don't get "read_friendlists" permission from
[FBRequestConnection startWithGraphPath:#"/me/permissions"....];
request.
I think this is the reason, why I can't get the full friend list.
I tried to get the list with the following methods:
[FBRequestConnection startWithGraphPath:#"me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSLog(#"FriendList: %#", result);
/* handle the result */
}];
AND
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"Found: %i friends", friends.count);
for (NSDictionary<FBGraphUser>* friendIns in friends) {
NSLog(#"I have a friend named %# with id %#", friendIns.name, friendIns.id);
}
}];
These methods give me the friends, who also use my app, and not the whole friend list.
What's wrong with my method(s)?
How to get the full friend list from user?
read_friendlists is not for getting friends, but only for getting the lists you created (without any friends in it). It also needs approval from Facebook before you can use it, but it´s definitely not what you want.
user_friends is for getting access to the friends who authorized your App too, with /me/friends. That would be the appropriate way.
There is no way to get ALL friends anymore, unless you want to tag friends (taggable_friends) or invite friends to a game on Facebook Canvas (invitable_friends).
I'm trying to get the user's friend list with iOS Facebook SDK 3.1 but I'm getting an empty list as a result. This is what I'm doing:
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(#"NAME %#", friend.name);
}
}];
I'm getting this:
{
data = (
); }
This app has also Facebook Login and it works OK. What am I missing?
Thanks in advance!