Zouvv
Zouvv

Reputation: 143

Swift/Objective-C Facebook SDK retrieving user data?

Facebook include no swift help in their Docs, just objective-c. This makes it hard to understand what to do when using say the Graph API.

The following objective-c code is supposed to get some user information:

if ([FBSDKAccessToken currentAccessToken]) {
    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
        startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
        if (!error) {
            NSLog(@"fetched user:%@", result);
        }
    }];
}

Could anyone explain how this would be done in swift?

Upvotes: 0

Views: 170

Answers (1)

Fantattitude
Fantattitude

Reputation: 1842

Translated the code to Swift :

if FBSDKAccessToken.currentAccessToken() != nil {
    FBSDKGraphRequest(graphPath: "me", parameters: nil).startWithCompletionHandler { (connection, result, error) in
        if error == nil {
            print("Fetched user : \(result)")
        }
    }
}

Upvotes: 3

Related Questions