iOS Facebook SDK - getting friends emails

纵饮孤独 提交于 2019-12-24 14:34:30

问题


I am developing an iPhone application, and I want to be able to list the user's friends who are connected to my application and access their e-mails, if they have already granted my application access to their e-mails.

This is the code I am using to open the Facebook session:

    - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {

     NSArray *permissions = [[NSArray alloc] initWithObjects:
                    @"email",
                    nil];

    return [FBSession openActiveSessionWithReadPermissions:permissions
                                      allowLoginUI:allowLoginUI
                                 completionHandler:^(FBSession *session,
                                                     FBSessionState state,
                                                     NSError *error) {
                                     [self sessionStateChanged:session
                                                         state:state
                                                         error:error];
                                 }];
}

Also, in a ViewController.m, I using the following code to list the friends and get their e-mails:

    NSString *query =
         [NSString stringWithFormat:@"SELECT name, uid, pic_small, birthday,proxied_email, contact_email , email FROM user WHERE is_app_user = 1 and uid IN (SELECT uid2 FROM friend where uid1 = %@) order by concat(first_name,last_name) asc", my_fb_uid ];

        // Set up the query parameter
       NSDictionary *queryParam =
      [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
       // Make the API request that uses FQL

    [FBRequestConnection startWithGraphPath:@"/fql"
                         parameters:queryParam
                         HTTPMethod:@"GET"
                  completionHandler:^(FBRequestConnection *connection,
                                      id result,
                                      NSError *error) {
                      if (error) {
                          NSLog(@"Error: %@", [error localizedDescription]);
                      } else {
                          NSLog(@"Result: %@", result);
                      }
                  }];  

The problem is that the returned e-mails are always null, even for friends who installed my application and authorized it to access their e-mails.

Any advice on this?


回答1:


From the documentation:

Note: There is no way for apps to obtain email addresses for a user's friends.

The email permission is only for the logged_in user




回答2:


What you should do is when a user grants access to their Facebook account, you should store their FB user ID. Then when trying to find a user's friends, pull a request of the user's FB friends (http://developers.facebook.com/docs/reference/ios/3.2/class/FBRequest#requestForMyFriends) and compare the IDs that are returned. This is the correct way of doing what you are wanting.



来源:https://stackoverflow.com/questions/15258910/ios-facebook-sdk-getting-friends-emails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!