简体   繁体   中英

How to fetch facebook user friends email ids in ios

m using facebook graph apis in my app. i want to fetch my fb friends email ids in a tableview in my app fb graph user doesn't provides any property for emails. how can i achive this help me - (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView { self.userInfoTextView.hidden = NO;

// Fetch user data
[FBRequestConnection
 startForMeWithCompletionHandler:^(FBRequestConnection *connection,
                                   id<FBGraphUser> user,
                                   NSError *error) {
     if (!error) {
         NSString *userInfo = @"";

         // Example: typed access (name)
         // - no special permissions required
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Name: %@\n\n",
                      user.name]];

         // Example: typed access, (birthday)
         // - requires user_birthday permission
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Birthday: %@\n\n",
                      user.birthday]];

         // Example: partially typed access, to location field,
         // name key (location)
         // - requires user_location permission
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Location: %@\n\n",
                      user.location[@"name"]]];



         // Example: access via key (locale)
         // - no special permissions required
         userInfo = [userInfo
                     stringByAppendingString:
                     [NSString stringWithFormat:@"Locale: %@\n\n",
                      user[@"locale"]]];


         // Example: access via key for array (languages)
         // - requires user_likes permission
         if (user[@"languages"]) {
             NSArray *languages = user[@"languages"];
             NSMutableArray *languageNames = [[NSMutableArray alloc] init];
             for (int i = 0; i < [languages count]; i++) {
                 languageNames[i] = languages[i][@"name"];
             }
             userInfo = [userInfo
                         stringByAppendingString:
                         [NSString stringWithFormat:@"Languages: %@\n\n",
                          languageNames]];
         }
                      // Display the user info
         self.userInfoTextView.text = userInfo;
     }
 }];

}

You cannot obtain e-mail addresses for friends through the Facebook API (with good reason - to prevent spam). You can obtain the current user's e-mail address, but only with an extended permission ( more about that here ).

Add this line to your code. Hope it will be helpful to you.

NSLog(@"%@",[user objectForKey:@"email"]);

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