如何使用移动中心用户签名功能获取用户详细信息?

时间:2017-12-09 12:36:42

标签: facebook aws-cognito aws-mobilehub amazon-cognito-facebook amazon-mobile-hub

我正在使用AWS Mobile Hub服务进行用户登录。我关注移动中心开发者指南,我成功地使用Facebook登录。记录之后 - 如何获取用户详细信息,如个人资料图片或名称或DOB等。移动中心的开发人员指南不解释这一点。是否可以获取详细信息,还是仅用于验证用户身份?

1 个答案:

答案 0 :(得分:0)

目前帮助您执行Facebook SignIn的AWS Auth SDK不支持检索用户个人资料信息,可直接使用Facebook iOS SDK获取包括用户名,imageURL等信息。

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