0

I am using AWS Mobile Hub for iOS and wanted help getting user details by using AWS Cognito identity pools.

For example after logging-in via Google and Facebook, along with the secret keys which Google and FB give, I also need the user-profile details like his Email-ID, Profile_picture from them.

It will be good if someone can post a SWIFT code for the same.

Reza Mousavi
  • 4,420
  • 5
  • 31
  • 48
Geo Joy
  • 347
  • 2
  • 10

1 Answers1

1

The following code snippets use the Facebook and Google SDK for iOS respectively.

For Facebook:

        import FBSDKCoreKit
        import FBSDKLoginKit

        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()

For Google:

import GoogleSignIn


let googleUser = GIDSignIn.sharedInstance().currentUser
self.userName = googleUser?.profile.name
self.imageURL = googleUser?.profile.imageURL(withDimension: GoogleSignInProviderProfileImageDimension)
Karthikeyan
  • 1,411
  • 1
  • 13
  • 13
  • I tried FB, It woks fine. But very less info is retried from FB, not the complete public profile. – Geo Joy Sep 21 '18 at 04:13