Facebooklogin – 获取用户数据

我正在使用Parse在iOS上构build一个应用程序作为后端。

为此,我使用Parse Facebook SDK,以便首先将Facebook链接到我的Parse用户,然后查询他的数据并保存它们。

问题是:有时我没有得到一些像电子邮件(用户数据[@“电子邮件”是零),名字,名称,或个人资料图片不会下载的一些信息。

不是所有的时间(实际上很less见),也不可能可靠地复制这个问题,所以我可以解决这个问题。 往往只有一个缺less的领域不是全部。

所以我在我的数据库中发现了漏洞(当用户的电子邮件地址是我的主要关注点时,并不酷)

这是我写我的方法(我编辑了大部分的if(错误)pipe理,使其更短)。

有任何想法吗 ?

感谢你们 !

NSArray *permissionsArray = @[@"public_profile",@"email", @"user_friends"]; [PFFacebookUtils initializeFacebook]; // Login PFUser using Facebook [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) { if (user.isNew) { NSLog(@"User with facebook signed up and logged in!"); [self fbData:self]; } else { NSLog(@"User with facebook logged in!"); [self fbDataAlreadyLog:self]; } }]; 

然后我调用我的“fbData”函数,以便将用户数据填入Parse:

 -(IBAction)fbData:(id)sender{ [PFFacebookUtils initializeFacebook]; FBRequest *request = [FBRequest requestForMe]; // Send request to Facebook [request startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *userCloud, NSError *error) { if (!error) { // result is a dictionary with the user's Facebook data NSDictionary *userData = userCloud; NSString *facebookID = userData[@"id"]; NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]]; PFUser *user = [PFUser currentUser]; if (userData[@"name"]) { user[@"name"] = userData[@"name"]; } if (userData[@"first_name"]) { user[@"first_name"] = userData[@"first_name"]; } if (userData[@"last_name"]) { user[@"last_name"] = userData[@"last_name"]; } if (userData[@"id"]) { user[@"fbID"] = userData[@"id"]; } if (userData[@"gender"]) { user[@"gender"] = userData[@"gender"]; } if (userData[@"email"]) { user.email = userData[@"email"]; user.username = userData[@"email"]; } if (userData[@"age_range"]) { user[@"age_range"] = userData[@"age_range"]; } SDWebImageManager *manager = [SDWebImageManager sharedManager]; [manager downloadImageWithURL:pictureURL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { // progression tracking code } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished,NSURL *imageURL) { if (image) { // do something with image NSData *imageNSData = UIImagePNGRepresentation(image); PFFile *imageFile = [PFFile fileWithName:@"profilePic" data:imageNSData]; user[@"image"] = imageFile; [user saveInBackgroundWithBlock]; //Once the Save Block is done I managed a few more thing before moving on to the next ViewController } }]; }]; 

试试这个

 NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];