我正在使用Parse loginViewController通过Facebook登录用户。我只是想弄清楚如何在Swift中调用Graph API。我在Parse上找到了以下内容
[PFFacebookUtils logInWithPermissions:permissionsArray block:(PFUseruser, NSError error) { if (user) {
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Store the current user's Facebook ID on the user
[[PFUser currentUser] setObject:[result objectForKey:@"id"]
forKey:@"fbId"];
[[PFUser currentUser] saveInBackground];
}
}];
} }];
但我似乎无法将其翻译成Swift。我试图在以下函数中运行它:
func logInViewController(controller: PFLogInViewController, didLogInUser user: PFUser) -> Void
答案 0 :(得分:1)
func logInViewController(logInController: PFLogInViewController!, didLogInUser user: PFUser!) -> Void
{
FBRequestConnection.startForMeWithCompletionHandler({connection, result, error in
if !error
{
PFUser.currentUser().setObject(result.id as? String, forKey: "fbId")
PFUser.currentUser().saveInBackground()
}
else
{
println("Error")
}
})
}
答案 1 :(得分:0)
func getFBData(user: PFUser!){
FBRequestConnection.startForMeWithCompletionHandler({connection, result, error in
if (error != nil) {
println(result)
}else {
println("Error")
}
})
}