Reputation: 199
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?
Upvotes: 1
Views: 4126
Reputation: 1031
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.
Upvotes: 4
Reputation: 2800
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
Upvotes: 19