我有一个注册/登录方法(来自PFFacebookUtilsV4),当新的Facebook用户登录时,它成功地将新的PFUser对象添加到我的Parse数据库。在该方法中,我创建了一个FBSDKGraphRequest来获取基本用户数据(名称,电子邮件) )。但是,我无法将名称和电子邮件添加到新创建的PFUser对象中。到目前为止,这是我的代码:
@IBAction func facebookLogin(sender: AnyObject) {
PFFacebookUtils.logInInBackgroundWithReadPermissions(["public_profile","email","user_friends"], block: { (user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"name,email,picture.width(480).height(480)"])
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
println("Error: \(error)")
ProgressHUD.showError("Error occurred.")
} else {
self.userFullName = result.valueForKey("name") as? String
println("User Name is: \(self.userFullName)")
self.userEmail = result.valueForKey("email") as? String
println("User Email is: \(self.userEmail)")
// Here I try to add the retrieved Facebook data to the PFUser object
user["fullname"] = self.userFullName
user.email = self.userEmail
self.performSegueWithIdentifier("login", sender: self)
println("User signed up and logged in through Facebook!")
ProgressHUD.showSuccess("Welcome \(self.userFullName)!")
}
})
} else {
println("User logged in through Facebook!")
ProgressHUD.showSuccess("Welcome \(self.userFullName)!")
self.performSegueWithIdentifier("login", sender: self)
}
} else {
println("User cancelled the Facebook login.")
}
})
}
谢谢!非常感谢任何帮助。
答案 0 :(得分:1)
在Facebook请求结束中添加新数据后保存用户。
user.saveEventually()
或者您喜欢的任何其他保存。