如何快速找到Parse用户的Facebook信息?

时间:2014-06-25 08:54:05

标签: facebook swift parse-platform

我正在使用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

2 个答案:

答案 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")
        }
    })
}