iOS Facebook获取用户的电子邮件 [英] iOS Facebook get user's e-mail

查看:166
本文介绍了iOS Facebook获取用户的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了超过2000个东西来获取用户的电子邮件。我不能从Facebook SDK的图形API获得它。它不包含电子邮件属性。我也试图手动添加电子邮件属性到FB框架,没有发生任何事情。是否可以下载与iOS 7兼容的第一个FB SDK?它还有电子邮件属性,不是吗?或者有什么其他方式如何获得真实的电子邮件,我必须与他们一起工作。我不需要example@facebook.com。

I tried over 2000 things to get the user's email. I can't get it from the Facebook SDK's graph API. It doesn't contain email property. I also tried to add manually the email property to the FB framework and nothing happened. Is it possible to download the first FB SDK which is compatible with iOS 7? Does it still have the email property, doesn't it? Or is there any other way how to get the REAL email, I must work with them. I don't need the example@facebook.com.

感谢任何建议。

编辑

NSArray *permissions = @[@"email", @"public_profile"];
    [PFFacebookUtils logInWithPermissions:permissions block:^(PFUser *user, NSError *error) {
        if (!user) {
            if (!error) {
                NSLog(@"The user cancelled the Facebook login.");
            } else {
                NSLog(@"An error occurred: %@", error.localizedDescription);
            }


            if ([delegate respondsToSelector:@selector(commsDidLogin:)]) {
                [delegate commsDidLogin:NO];
            }
        } else {
            if (user.isNew) {
                NSLog(@"User signed up and logged in through Facebook!");
            } else {
                NSLog(@"User logged in through Facebook!");
            }

            [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                if (!error) {
                    PFUser *usere = [PFUser currentUser];
                    [usere setObject:[result objectForKey:@"first_name"] forKey:@"name"];
                    [usere setObject:[result objectForKey:@"last_name"] forKey:@"surname"];
                 //   [usere setObject:[result objectForKey:@"email"] forKey:@"mail"];
                    [usere saveEventually];
                     NSLog(@"user info: %@", result);
                        }
            }];

                }
                if ([delegate respondsToSelector:@selector(commsDidLogin:)]) {
                    [delegate commsDidLogin:YES];
                }
            }];
        }


推荐答案

我没有图形代码API,

I have not code for graph API,

但是新的facebook sdk版本3,我有代码。

but with new facebook sdk version 3, I have code for that.

-(void)openFbSession
{
    [[self appDelegate].session closeAndClearTokenInformation];

    NSArray *permissions =     [NSArray arrayWithObjects:@"email",@"user_location",@"user_birthday",@"user_hometown",nil];
    [self appDelegate].session = [[FBSession alloc] initWithPermissions:permissions];

    [[self appDelegate].session openWithCompletionHandler:^(FBSession *session,
                                                            FBSessionState status,
                                                            NSError *error) {
        if(!error)
        {
            NSLog(@"success");
            [self myFbInfo];
        }
        else
        {
            NSLog(@"failure");
        }

    }];
}

对于所有信息,myFbInfo方法是

and for all information, myFbInfo method is

-(void)myFbInfo
{
    [FBSession setActiveSession:[self appDelegate].session];

    [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
        if (error) {
            // Handle error
        }

        else {
            //NSString *userName = [FBuser name];
            //NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser id]];
            NSLog(@"Name : %@",[FBuser name]);
            NSLog(@"first name : %@",[FBuser first_name]);
            NSLog(@"Last name : %@",[FBuser last_name]);
            NSLog(@"ID : %@",[FBuser id]);
            NSLog(@"username : %@",[FBuser username]);
            NSLog(@"Email : %@",[FBuser objectForKey:@"email"]);

            NSLog(@"user all info : %@",FBuser);

              }
    }];

}






编辑


EDIT

在appdelegate.h

in appdelegate.h

@property (strong, nonatomic) FBSession *session;

在appdelegate.m

in appdelegate.m

- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation
{
    //NSLog(@"FB or Linkedin clicked");
    return [self.session handleOpenURL:url];
}


- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [FBSession.activeSession handleDidBecomeActive];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    [self.session close];
}

这篇关于iOS Facebook获取用户的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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