【问题标题】:How to print the public details like first name, last name or email in Facebook SDK 4.18.0 in swift3?如何在 swift3 中打印 Facebook SDK 4.18.0 中的名字、姓氏或电子邮件等公共详细信息?
【发布时间】:2017-01-19 07:05:31
【问题描述】:

我正在使用 FBSDK4.18.0 在 iOS 中以 Swift3 语言集成 Facebook 登录。下面是以下代码:但确实如此 不打印结果,包括

     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)")
                    }
                }
            }
        }
    }

它还显示了“来自 'FBSDKLoginManagerLoginResult!' 的演员表!”到不相关的类型 '[String : Any]' 总是失败”警告在“if let dic = result as?[String: Any]”

【问题讨论】:

    标签: ios swift3 facebook-sdk-4.0


    【解决方案1】:

    您应该使用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)")
           }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 2014-05-17
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多