我是NewBie,Facebook登录iOS for Facebook登录我制作了一个FbView,我写了一个代码,用于获取电子邮件和用户名称然后它是给我的用户名,因为我想要但电子邮件地址得到Null请给我解决方案。
这里我的代码就像
一样- (void)viewDidLoad
{
[super viewDidLoad];
self.fbView.readPermissions = @[@"public_profile", @"email", @"user_friends"];
self.fbView.delegate=self;
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended)
{
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
NSLog(@"Email %@",[user objectForKey:@"email"]);
NSLog(@"User Name %@",user.username);
}
}];
}
我也写了一个方法用于获取电子邮件,如
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user
{
NSLog(@"User Name %@",user.name);
NSLog(@"Email %@",[user objectForKey:@"email"]);
}
但它给了我NULL
价值请给我解决方案。
答案 0 :(得分:1)
根据您的第二种方法,尝试这样,
-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
NSString *userDetails = [NSString stringWithFormat:@"%@",user];
NSString *fb_userEmail = [user objectForKey:@"email"];
}
userDetails
将返回单个字符串对象中的所有用户详细信息。
fb_userEmail
将返回用户的电子邮件ID。