gpt4 book ai didi

ios - 无法从 facebook、ios 获取电子邮件。始终获取 null

转载 作者:行者123 更新时间:2023-11-29 01:39:22 25 4
gpt4 key购买 nike

-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user ////////////////////////////// fetch logged in user information
{
if (FBSession.activeSession.isOpen) {

[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
NSString *firstName = user.first_name;
NSString *lastName = user.last_name;
NSString *facebookId = user.id;
NSString *email = [user objectForKey:@"email"];
NSString *imageUrl = [[NSString alloc] initWithFormat: @"http://graph.facebook.com/%@/picture?type=large", facebookId];
NSLog(@" f0000000 %@",imageUrl);
NSLog(@" email ===== %@",email);
}
}];
}



NSString *email_id= [user objectForKey:@"email"];
NSLog(@" fetch yo ----->%@",user.name); /////

NSLog(@" object ----->%@",email_id);


}

输出------------

f0000000 http://graph.facebook.com/******/picture?type=large
email ===== (null)

f0000000 http://graph.facebook.com/*****/picture?type=large
email ===== (null)

我收到的电子邮件为空。我如何获取用户或当前登录用户的电子邮件。我是 ios 新手,不知道该怎么做。

最佳答案

我真的应该只是解释而不是发布一堆代码,但有时查看代码是了解一切如何协同工作的最佳方式。以下是我在应用程序中进行 Facebook 登录的方法:

// FBSample logic
// The user has initiated a login, so call the openSession method.

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile", @"email", @"user_friends"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
NSLog(@"ERROR SIGNING IN");
[self loginFailed];
} else if (result.isCancelled) {
// Handle cancellations
NSLog(@"login cancelled");
[self loginFailed];
} else {
NSLog(@"here 1");
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:@"email"]) {
// Do work
NSLog(@"here 2");

NSUserDefaults *fbstatus = [NSUserDefaults standardUserDefaults];
[fbstatus setValue:@"NO" forKey:@"FBStatus"];
[fbstatus synchronize];

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, first_name, last_name, gender, picture, email, birthday, about, address, age_range, bio, currency, devices, education, favorite_athletes, favorite_teams, hometown, inspirational_people, interested_in, location, political, sports, security_settings, relationship_status, quotes, timezone, website, work, cover, family, photos, videos, friendlists, groups, permissions"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{

if (!error)
{
NSLog(@"here 3");
NSDictionary *userData = (NSDictionary *)result;
// userData contains your FBSDKGraphRequest results
// do whatever you need to do now that you have Facebook data
} else {
NSLog(@"ERROR GETTING FB DATA");
}

}];
}
}}];

NSDictionary *userData 将包含您有权访问的所有 Facebook 信息。希望这可以帮助。不要只是复制和粘贴,请仔细阅读它,以便您了解它是如何工作的!

关于ios - 无法从 facebook、ios 获取电子邮件。始终获取 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32587943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com