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!
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.
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 am trying fetch my Friends who are using my application from facebook and but in the response i am getting empty list list. Please guide me what i am doing wrong. I am using the following code
[[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
//error
NSLog(#"%#",error);
}else{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,NSDictionary* result,NSError *error) {
NSArray* friends = [result objectForKey:#"data"];
NSLog(#"%#",result);
for (NSDictionary<FBGraphUser>* friend in friends)
{
NSLog(#"%# %d",friend.username,[friend.id intValue]);
}
}];
}
}];
Thanks
Possible reasons:
1) You don't have the rights to get connections of this account (wrong apikey/passkey or rights not properly set)
2) Check what is stored in "result" variable and the answer status: it may guide you in some way.
3) Finally, try to get some simpler informations (like your own username) to be sure you have access to these informations.
In the new version of Facebook's API you will get ONLY friends that installed the app (i.e. is_app_user is 1).
You can't get friends who haven't logged in with your app anymore.
Instead, you can get taggable_friends. This will return a list with all of your friends, but here "id" field will be different, not the real facebook id. Its only for tagging, i.e. for passing to field "tags" like:
NSDictionary *params = #{#"message":self.invitationText.text,
#"tags":ids,
#"caption":#"...",
#"name":#"...",
#"place":#"123456789",
#"link":APP_STORE_URL};
[FBRequestConnection startWithGraphPath:#"/me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//...
}];
i am getting null in friends list this is my code
-(void)getFriendList
{
FBRequest *friendsRequest=[FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
{
arrFriendFB = [result objectForKey:#"data"];
arrFriendFB=[arrFriendFB valueForKey:#"first_name"];
NSLog(#"friemd=%#",arrFriendFB);
NSLog(#"friends description :%#",[arrFriendFB description]);
}];
}
As new facebook APi doc there is some modification. see some change's mention below
first you need to get access token with "user_friends" permission.
its graph API url:-
https://graph.facebook.com/me/friends?access_token=
For more information follow this link
https://developers.facebook.com/docs/facebook-login/permissions/v2.0
use this method to get friend list.
-(void)getFriendList
{
[FBSession setActiveSession:[self appDelegate].session];
FBRequest *friendRequest = [FBRequest requestForGraphPath:#"me/friends?fields=name,picture,location"];
[ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSArray *data = [result objectForKey:#"data"];
//NSLog(#"response : %#",data);
for (FBGraphObject<FBGraphUser> *friend in data)
{
NSLog(#"name : %#",[friend name]);
}
}];
}
I am trying to get a list of all my Facebook Friends, who are using the App I am getting the list of all friends, but how do I filter all the friends which are using the app?
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);
}
NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
return friend.id;
}];
}];
Thanks.
Thats the way how it works with iOS5+
FBRequest* friendsRequest = [FBRequest requestWithGraphPath:#"me/friends?fields=installed" parameters:nil HTTPMethod:#"GET"];
[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);
}
NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
return friend.id;
}];
}];
This can be used for latest Facebook API 3.2 ,
[FBRequestConnection startForMyFriendsWithCompletionHandler:
^(FBRequestConnection *connection, id<FBGraphUser> friends, NSError *error)
{
if(!error){
NSLog(#"results = %#", friends);
}
}
];
"is_app_user" that you need to check.
- (void)getFriends
{
NSString *query = #"select uid, name, is_app_user "
#"from user "
#"where uid in (select uid2 from friend where uid1=me() )";
NSDictionary *queryParam =
[NSDictionary dictionaryWithObjectsAndKeys:query, #"q", nil];
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
DLog(#"Error: %#", [error localizedDescription]);
[self.delegate FBDidFailedLoadFriends:error];
} else {
DLog(#"Result: %#", result);
}
DLog(#"%#",((FBGraphObject*)result)[#"data"]);
}];
}
You can do it with FQL. It will directly give list of friends who are using app.
SELECT uid FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ?)
AND is_app_user = 1
Should be closed as Facebook has changed the way you can access the friends list.
Now all you can access is app users.