如何获取将其Facebook帐户与我的Parse应用程序“链接”的用户的Facebook ID?我看到有一个authData
列,但是当我请求该类时,它只返回选择列。我怎么能这样做?
答案 0 :(得分:5)
使用解析自己的方法,使用facebook api FBRequestConnection
获得用户的脸谱ID[PFFacebookUtils logInWithPermissions:[NSArray arrayWithObject:@"email"] block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew) {
NSLog(@"User signed up and logged in through Facebook!");
[FBRequestConnection startWithGraphPath:@"/me"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
NSString *facebookID = result[@"id"];
NSString *nameF = result[@"first_name"];
NSString *nameL = result[@"last_name"];
NSString *gender = result[@"gender"];
NSString *email = result[@"email"];
NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]];
NSData *imageData = [NSData dataWithContentsOfURL:pictureURL];
//UIImage *fbImage = [UIImage imageWithData:imageData];
PFFile *imageFile = [PFFile fileWithName:@"Profileimage.png" data:imageData];
PFUser *user = [PFUser currentUser];
user[@"email"] = email;
user[@"User_first_name"] = nameF;
user[@"User_last_name"] = nameL;
user[@"User_gender"] = gender;
user[@"user_image"] = imageFile;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
// The currentUser saved successfully.
} else {
// There was an error saving the currentUser.
}
}];
/* handle the result */
}];
} else {
}
}];
在此您可以看到我获得用户的完整个人资料.. 谢谢,可能会帮到你...