我正在将我的应用升级到Facebook-iOS-SDK-4.0,但似乎我无法从FBSDKProfile获得用户邮箱,因为它只提供用户名、用户名、用户ID等.

推荐答案

要获取邮箱,您需要利用graph API,特别是提供用所需字段填充的参数字段.看一看Facebook的Graph API explore工具,它可以帮助找出这些查询.https://developers.facebook.com/tools/explorer

我获取邮箱的代码如下,假设您已经登录:

    NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
    [parameters setValue:@"id,name,email" forKey:@"fields"];

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                  id result, NSError *error) {
         aHandler(result, error);
     }];

Objective-c相关问答推荐

将 NSInteger 变量传递给 NSMutableDictionary 或 NSMutableArray

如何从 Appdelegate 显示 UIAlertController

使用 CALayer 时无法编译代码

将 CSS 插入 UIWebView / WKWebView 中加载的 HTML

NSFileManager 唯一的文件名

在 UILabel.attributedText *not* 蓝色和 *not* 下划线

如何获取 AppIcon 的 UIImage?

NSUInteger 不应该在格式字符串中使用吗?

iOS 中 textField 上的Electron邮件验证

实现 -hash / -isEqual: / -isEqualTo...: 用于 Objective-C 集合

在 NSString 对象中查找子字符串

Electron邮件镇静 iOS 8

如何在 Objective-C 中创建一个空白的透明 png?

在字符串Objective-c中连接字符串

如何在 UIImageView 中显示 base64 图像?

如何查看 NSError?

Cocoapods ld:找不到-lPods-Projectname 的库

NSAssert vs assert :您使用哪个,何时使用?

UIDatePicker 中的最小和最大日期

@package 指令在 Objective-C 中的作用是什么?