How to get email id of user using facebook sdk 4.7 in ios 9

依然范特西╮ 提交于 2019-11-26 18:40:42

问题


Here is my code , I am only getting user name and facebook id of user.

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)"

FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter


回答1:


I am using pod for Facebook sdk and it's work in iOS9.0 with 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();

        }
    }
}]


来源:https://stackoverflow.com/questions/33513630/how-to-get-email-id-of-user-using-facebook-sdk-4-7-in-ios-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!