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"];
- 从Login ViewController提供先前活动的ViewController
- 如何对asynchronous事件(login)作出反应?
- 是否可以在iOS应用程序的twitter中login,而不是使用存储在设备设置中的Twitter帐户?
- 您好,我正在使用Quickblox API在我的应用程序中聊天。 但我有问题相关的密码长度
- TouchIDlogin用户与iOS 8.0中的数据库Parse.com
- 使用GIDSignIn单击时,“URL scheme com-google-gidconsent”没有注册的处理程序错误
- 使用GIDSignIn.sharedInstance.clientID =时的错误代码
- 终止应用程序,由于未捕获的exception'NSInvalidArgumentException' – ios谷歌login
- 自定义Google Sign In在GIDSignInDelegate协议上抛出exception