如何在 swift3 的 Facebook SDK 4.18.0 中打印名字、姓氏或电子邮件等 public 详细信息?

How to print the public details like first name, last name or email in Facebook SDK 4.18.0 in swift3?

我正在iOS使用FBSDK4.18集成Swift3语言的facebook登录。0.Below是下面的代码:但是它确实 不打印结果,包括

     func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
        print("User Logged In")
        if ((error) != nil)
        {
            // Process error
        }
        else if result.isCancelled {
            // Handle cancellations
        }
        else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if result.grantedPermissions.contains("public_profile")
            {
                // Do work
//                let strFirstName: [String: Any]? = (result.objectForKey("first_name") as? String)!
//                let strLastName: String = (result.objectForKey("last_name") as? String)!
//                let strPictureURL: String = (result.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as? String)!

                if let dic = result as? [String: Any]
                { if let strFirstName = dic["first_name"] as? String, let strLastName = dic["last_name"] as? String
                {
                    print("\(strFirstName) \(strLastName)")
                    }
                }
            }
        }
    }

它还在 "if let dic = result as? [String: Any]"[=12 处显示“从 'FBSDKLoginManagerLoginResult!' 转换为不相关类型‘[String : Any]’总是失败”警告=]

您应该使用 AnyObject 而不是 Any。可以找到更多关于它的信息 here:

if let dic = result as? [String: AnyObject] { 
   if let strFirstName = dic["first_name"] as? String, let strLastName = dic["last_name"] as? String
       {
          print("\(strFirstName) \(strLastName)")
       }
 }