How to get the user details using mobile hub User-sign feature?

168 views Asked by At

I'm using AWS Mobile Hub service for user sign-in. I follow mobile hub developer guide and i was successfully able to login using Facebook. After logging -in how to get the user details like profile picture or name or DOB etc. The developers guide of the mobile hub doesn;t explain this. Is it possible to get the details or is it only to authenticate users?

1

There are 1 answers

0
Karthikeyan On BEST ANSWER

Currently the AWS Auth SDK which helps you perform Facebook SignIn doesn't support retrieving the user profile information can directly use the Facebook iOS SDK to fetch information including username, imageURL, etc.

        let imageGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "picture.type(large)"])
        let imageConnection = FBSDKGraphRequestConnection()
        imageConnection.add(imageGraphRequest, completionHandler: { (connection, result, error) in
            guard let imageResult = result as? NSDictionary else  { return}
            if let imageURL = URL(string:(((imageResult.value(forKey: "picture") as AnyObject).value(forKey: "data") as AnyObject).value(forKey: "url") as? String)!) {
                self.imageURL = imageURL
            }
        })
        imageConnection.start()

        let userGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, email"])
        let userConnection = FBSDKGraphRequestConnection()
        userConnection.add(userGraphRequest, completionHandler: { (connection, result, error) in
            guard let userResult = result as? NSDictionary else { return }
                if let userName = userResult.value(forKey: "name")  as? String {
                    self.userName = userName
                }
        })
        userConnection.start()