如何在ios 9中使用facebook sdk 4.7获取用户的电子邮件ID [英] How to get email id of user using facebook sdk 4.7 in ios 9

查看:114
本文介绍了如何在ios 9中使用facebook sdk 4.7获取用户的电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我只获取用户名和用户的Facebook ID。

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:URL失败:fbauth2:/ - 错误:(null) - scanOpenURL:URL失败:fbauth2:/ - 错误:(null)

-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)" -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

FBSDKLog:从Graph API v2.4开始,/ b的GET请求应该是
包含一个明确的fields参数

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


推荐答案

我正在使用pod for Facebook sdk,它在iOS9.0中使用xcode 7.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();

        }
    }
}]

这篇关于如何在ios 9中使用facebook sdk 4.7获取用户的电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆