0

I'm trying to get FaceBook Friend list , and display it in custom view like "foresqure App"

what I mean "foursquare" ask for the permission and to post on your wall inside the app without leaving the app to the browser or to the app Facebook ? after that the app get all friends and display it in custom tableView.

enter image description here

here what I tried :

if (!FBSession.activeSession.isOpen) {
    // if the session is closed, then we open it here, and establish a handler for state changes
    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"]
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState state,
                                                      NSError *error) {
                                      if (error) {
                                          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                              message:error.localizedDescription
                                                                                             delegate:nil
                                                                                    cancelButtonTitle:@"OK"
                                                                                    otherButtonTitles:nil];
                                          [alertView show];
                                      } else if (session.isOpen) {
                                          //[self pickFriendsButtonClick:sender];
                                          NSLog(@"aaaa");
                                          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);
                                              }
                                          }];
                                      }
                                  }];

}

In this case it will open the safari to ask for permision not inside the app and friend array allows nill or count = 0.

Omarj
  • 1,151
  • 2
  • 16
  • 43
  • @DarshanKunjadiya check this http://www.filedropper.com/testface – Omarj May 08 '14 at 10:38
  • in my mac this code is work perfectly . i am change only my facebook app id and get all friend list . – Darshan Kunjadiya May 08 '14 at 11:02
  • I had this bug when I forgot to check Native iOS App (in Facebook Developers Page) and typed-in my Bundle ID, which is same as Bundle identifier in your Xcode project. (including your project name at the end.) I also had the setting in Facebook Developers Page which enabled SandBox mode. I disabled Sandbox mode too to get this work. – Darshan Kunjadiya May 08 '14 at 11:06

1 Answers1

0

Try this code ..

Firstly call this method like this ..

[self FBFriendList];

And add this two methods.

-(void)FBFriendList
{
if (!FBSession.activeSession.isOpen)
{
    // if the session is closed, then we open it here, and establish a handler for state changes

    [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
     {
         if (error)
         {
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             [alertView release];
         }
         else if(session.isOpen)
         {
             [self FBFriendList];
             [self fb_frnd_use_this_app];
         }
     }];

    return;
}
}

-(void)fb_frnd_use_this_app
   {
    FBRequest *request =  [FBRequest  requestWithGraphPath:@"me/friends"
                                                parameters:@{@"fields":@"name,installed,first_name,picture"}
                                                HTTPMethod:@"GET"];

    [request startWithCompletionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)
     {


         NSLog(@"%@",result);
         int count = 0;
         NSMutableArray *frnd_arr = [result objectForKey:@"data"];
         for (int i = 0; i < [frnd_arr count]; i++)
         {
             NSLog(@"%@",frnd_arr);
             count++;
         }

         NSLog(@"%@",app.Arr_Facebook_Frnd);
         app.fbfriendCount =[NSString stringWithFormat:@"%d",count];

     }];
}

Hope this code is useful for you.

Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31