Created
March 1, 2016 22:44
-
-
Save makthrow/586da4704100f7945281 to your computer and use it in GitHub Desktop.
FBSDK get facebook usr info function in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getFBUserInfo() { | |
let facebookRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "name, gender, picture, birthday, first_name, last_name"]) | |
facebookRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result, error) -> Void in | |
if error == nil { | |
print ("result: \(result)") | |
var r = result as! NSDictionary | |
let firstName = r["first_name"] | |
let gender = r["gender"] | |
var dateFormatter = NSDateFormatter() | |
dateFormatter.dateFormat = "MM/dd/yyyy" | |
let birthday = dateFormatter.dateFromString(r["birthday"]! as! String) | |
let facebookID = r["id"]! | |
print ("facebookID: \(facebookID)") | |
let urlString = "https://graph.facebook.com/\(facebookID)/picture?type=large" | |
// get the URL of a larger picture | |
let largerPicURL = NSURL(string: urlString) | |
print (largerPicURL) | |
let request = NSURLRequest(URL: largerPicURL!) | |
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: { | |
response, data, error in | |
// TODO: save largerPic to DB | |
}) | |
} | |
else { // facebookRequest.startWithCompletionHandler | |
print (error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment