[英]How to get email id of user using facebook sdk 4.7 in ios 9
Here is my code , I am only getting user name and facebook id of user. 这是我的代码,我只获得用户名和用户的facebook ID。
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile",@"email",@"user_friends"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
} NSLog(@"Results=%@",result);
NSLog(@"Logged in");
}
}];
and it also give some error like this - 而且还会给出这样的错误-
-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)" -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
-canOpenURL:URL失败:“ fbauth2:/”-错误:“(null)” -canOpenURL:URL失败:“ fbauth2:/”-错误:“(null)”
FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter
FBSDKLog:从Graph API v2.4开始,针对/ me的GET请求应包含一个明确的“字段”参数
I am using pod for Facebook sdk and it's work in iOS9.0 with xcode 7.1. 我使用的是Facebook sdk的pod,它可以在iOS9.0中使用xcode 7.1。 Try this code
试试这个代码
void (^sendRequestsBlock)(void) = ^{
FBSDKGraphRequest *postRequest = nil;
NSDictionary *parameters = [NSDictionary dictionaryWithObject:@"id,email,first_name,last_name,name,picture{url}" forKey:@"fields"];
postRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters HTTPMethod:@"GET"];
[postRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
if (!error) {
NSDictionary *dictResult = (NSDictionary *)result;
}
}];
};
/// login start
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
NSArray *permissions = [NSArray arrayWithObjects:@"email",@"public_profile", nil];
[login logInWithReadPermissions:permissions fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
} else if (result.isCancelled) {
} else {
if ([result.grantedPermissions containsObject:@"email"]) {
sendRequestsBlock();
}
}
}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.