将 Facebook "name" 添加到 swift 中的 PFUser ["fullname"]
Add Facebook "name" to PFUser ["fullname"] in swift
我有一个 registration/login 方法(来自 PFFFacebookUtilsV4),当新的 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.")
}
})
}
谢谢!非常感谢任何帮助。
在 Facebook 请求闭包中添加新数据后保存用户。
user.saveEventually()
或您喜欢的任何其他存档。
我有一个 registration/login 方法(来自 PFFFacebookUtilsV4),当新的 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.")
}
})
}
谢谢!非常感谢任何帮助。
在 Facebook 请求闭包中添加新数据后保存用户。
user.saveEventually()
或您喜欢的任何其他存档。