简体   繁体   中英

Retrieve the friends Email address From Facebook SDK in ios

I am tried to retrieve the Email Address from Facebook Friends.but,It cannot retrieved the email address.

I printed the email address.but,It displays the null.

I added email address in permissions array,FBRequest.

-(void)LoginButtonTapped
{

    [FBSession.activeSession openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState state,
                                                         NSError *error)
     {


         if (FBSession.activeSession.isOpen)
         {

             NSLog(@"TOKEN : %@",[[FBSession activeSession]accessTokenData]);

             FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,picture,birthday,email,location"];
             [friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
              {
                  NSArray *data = [result objectForKey:@"data"];
                  for (FBGraphObject<FBGraphUser> *friend in data)
                  {
                      [delegate.friendsListArray addObject:friend];
                      NSLog(@"%@:%@:%@:", [friend name],[friend birthday],[friend id]);
                      NSString *email=[friend objectForKey:@"email"];
                      NSLog(@"Email:%@",email);

                  }


              }];

         }

     }];



}


- (void) performPublishAction:(void (^)(void)) action

{

    NSArray *permissions = [[NSArray alloc] initWithObjects:@"user_birthday",@"user_location",@"friends_email",@"friends_hometown",@"friends_birthday",@"friends_location",@"publish_actions",@"user_photos",nil];

    [[delegate facebook]authorize:permissions];

    if ([FBSession.activeSession.permissions indexOfObject:permissions] == NSNotFound)
    {

        [FBSession.activeSession requestNewPublishPermissions:permissions
                                              defaultAudience:FBSessionDefaultAudienceFriends
                                            completionHandler:^(FBSession *session, NSError *error) {
                                                if (!error) {
                                                    action();
                                                }
                                            }];
    }
    else
    {
        action();
    }

    [permissions release];

}

Any ideas please help me.

Shot in the dark but did you check your error value? Also what's the count of the # of records you get back?

Also could just try this instead, which seems to work (you might need to use objectForKey to get email out of the object):

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);
    }
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM