我正在升级我的应用程序到Facebook-iOS-SDK-4.0,,但似乎我无法从FBSDKProfile获得用户电子邮件,因为它只提供,用户名,用户I等。
发布于 2015-07-14 13:54:43
要获取电子邮件,您需要利用图形API,特别是提供由您想要的字段填充的参数字段。看看Facebook的Graph探索工具,它可以帮助理解查询。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);
}];发布于 2015-03-29 01:45:55
是这样的。电子邮件地址不存在于FBSDKProfile对象中。您应该使用FB的Graph代替。在FB开发人员站点https://developers.facebook.com/docs/ios/graph上有大量的信息和代码示例。
要回答你的问题,试试这样的方法。
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"user:%@", result);
}
}];
}发布于 2015-04-27 13:13:56
修正代码:
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}https://stackoverflow.com/questions/29323244
复制相似问题