Facebook iOS SDK - get friends list Facebook iOS SDK - get friends list ios ios

Facebook iOS SDK - get friends list


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: %lu friends", (unsigned long)friends.count);    for (NSDictionary<FBGraphUser>* friend in friends) {        NSLog(@"I have a friend named %@ with id %@", friend.name, friend.objectID);    }}];


Here is a more complete solution:

In your header file:

@interface myDelegate : NSObject <UIApplicationDelegate, FBSessionDelegate, FBRequestDelegate> {    Facebook *facebook;    UIWindow *window;    UINavigationController *navigationController;    NSArray *items; // to get facebook friends}@property (nonatomic, retain) IBOutlet UIWindow *window;@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;@property (nonatomic, retain) Facebook *facebook;@property (nonatomic, retain) NSArray *items;@end

Then in your implementation:

@implementation myDelegate@synthesize window;@synthesize navigationController;@synthesize facebook;@synthesize items;- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {...    facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID_FROM_FACEBOOK" andDelegate:self];    [facebook requestWithGraphPath:@"me/friends" andDelegate:self];    return YES;}

Then you need at least the following delegate protocol method:

- (void)request:(FBRequest *)request didLoad:(id)result {    //ok so it's a dictionary with one element (key="data"), which is an array of dictionaries, each with "name" and "id" keys    items = [[(NSDictionary *)result objectForKey:@"data"]retain];    for (int i=0; i<[items count]; i++) {        NSDictionary *friend = [items objectAtIndex:i];        long long fbid = [[friend objectForKey:@"id"]longLongValue];        NSString *name = [friend objectForKey:@"name"];        NSLog(@"id: %lld - Name: %@", fbid, name);    }}


To get list of friends you can use

https://graph.facebook.com/me/friends

[facebook requestWithGraphPath:@"me/friends"                     andParams:nil                   andDelegate:self];

To know more about all the possible API please read

https://developers.facebook.com/docs/reference/api/


matomo