I am using below code to get Facebook friend that uses app
// Issue a Facebook Graph API request to get your user\'s friend list
FBSDKGraphRequest *requ
Its not possible to get FriendList or EmailId of Friends, according to new API version, but if You want show FriendList use TaggableFriend Feature of Facebook.This Taggable API needs Approval from Facebook and this API returns id, Friend name, Profile picture URL.but Id is not FacebookId its Id for Post on wall.This only way to get friends.But if you use me/friends it return total number of friends and friend List of app User. Since you you don't have app user it only showing total Count of Friend.To implement this Feature you login with Admin Account(The Account from which Facebook ID Created)for this you have to implement the paging Concept.
Use this Code Spinnet: "/me/taggable_friends?fields=id,name,picture.type(large).
You have to add permission at login time user_friends
A user access token with user_friends
permission is required to view any of that person's friend lists.
you can get only that friends who installed the same apps,
Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me/friends"
parameters:nil
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
You can get the friend list and many others Detail like this :
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
custom Facebook Button click :
- (IBAction)facebook_click:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
// Process error
NSLog(@"error is :%@",error);
}
else if (result.isCancelled)
{
// Handle cancellations
NSLog(@"error is :%@",error);
}
else
{
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"Login successfull");
[self fetchUserInfo];
[login logOut];
}
}
}];
}
Response of Request :
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id,name,link,first_name, last_name, picture.type(large), email, birthday,friends,gender,age_range,cover"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
//NSLog(@"result is :%@",result);
NSLog(@"User ID : %@",[result valueForKey:@"id"]);
NSLog(@"User Name : %@",[result valueForKey:@"name"]);
NSLog(@"User First Name :%@",[result valueForKey:@"first_name"]);
NSLog(@"User Last Name :%@",[result valueForKey:@"last_name"]);
NSLog(@"USER Email is :%@",[result valueForKey:@"email"]);
NSLog(@"User fb_Link : %@",[result valueForKey:@"link"]);
NSLog(@"User Birthday : %@",[result valueForKey:@"birthday"]);
NSLog(@"FB Profile Photo Link :%@",[[[result valueForKey:@"picture"]objectForKey:@"data"]objectForKey:@"url"]);
NSLog(@"User total friends : %@",[[[result valueForKey:@"friends"]objectForKey:@"summary"]valueForKey:@"total_count"]);
NSLog(@"User Gender : %@",[result valueForKey:@"gender"]);
NSLog(@"User age_range : %@",[[result valueForKey:@"age_range"]objectForKey:@"min"]);
NSLog(@"User cover Photo Link : %@",[[result valueForKey:@"cover"]objectForKey:@"source"]);
//Friend List ID And Name
NSArray * allKeys = [[result valueForKey:@"friends"]objectForKey:@"data"];
fb_friend_Name = [[NSMutableArray alloc]init];
fb_friend_id = [[NSMutableArray alloc]init];
for (int i=0; i<[allKeys count]; i++)
{
[fb_friend_Name addObject:[[[[result valueForKey:@"friends"]objectForKey:@"data"] objectAtIndex:i] valueForKey:@"name"]];
[fb_friend_id addObject:[[[[result valueForKey:@"friends"]objectForKey:@"data"] objectAtIndex:i] valueForKey:@"id"]];
}
NSLog(@"Friends ID : %@",fb_friend_id);
NSLog(@"Friends Name : %@",fb_friend_Name);
}
}];
}
}
You can get Friends Profile Pic using this API.
NSString *str = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large",friend_id];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];
UIImage *profilePic = [UIImage imageWithData:imageData];
Note : it will only display the Friends list who is download your application. Not all friends of your facebook friends. Its not possible to get FriendList or EmailId of Friends, according to new API version