[英]iOS Facebook SDK - getting friends emails
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. 我正在开发iPhone应用程序,如果他们已经授予我的应用程序访问电子邮件的权限,我希望能够列出连接到我的应用程序并访问其电子邮件的用户朋友。
This is the code I am using to open the Facebook session: 这是我用来打开Facebook会话的代码:
- (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: 另外,在ViewController.m中,我使用以下代码列出朋友并获取他们的电子邮件:
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? 有什么建议吗?
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 email
权限仅适用于登录用户
What you should do is when a user grants access to their Facebook account, you should store their FB user ID. 您应该做的是,当用户授予对其Facebook帐户的访问权限时,您应该存储其FB用户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.
然后,在尝试查找用户的朋友时,拉出用户的FB朋友的请求( http://developers.facebook.com/docs/reference/ios/3.2/class/FBRequest#requestForMyFriends )并比较返回的ID。 This is the correct way of doing what you are wanting.
这是做自己想要的事情的正确方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.