图表请求 Facebook iOS swift 不工作 我正在尝试获取用户数据并将其上传到应用程序 Cloud Firestore

Graph request Facebook iOS swift not working Im trying to take the user data and upload it into app Cloud Firestore

@IBAction func buttTapped(_ sender: Any) {

func facebookLogin(){
        let loginManager = LoginManager()
       loginManager.logIn(permissions: ["publicProfile", "email"], from: self) { loginResult in
                   switch loginResult {
                   case .failed(let error):
                       print(error)
                   case .cancelled:
                       print("User cancelled login.")
                   case .success(let grantedPermissions, let declinedPermissions, let accessToken):
                    print("Logged in!")
                    self.fetchUserProfile()
                 }
           }

   }


}//

这是下面的 fetchuserprofile 函数

func fetchUserProfile() {
      let graphRequest : GraphRequest = GraphRequest(graphPath: "me", parameters:   ["fields":"id, email, name, picture.width(480).height(480)"])

    graphRequest.start(completionHandler: { (connection, result, error) -> Void in
         if ((error) != nil)
        {
             print("Error took place: \(error ?? "" as! Error)")
        }
        else
        {
            let result = result as! Dictionary<String, Any>
            let picture = result["picture"] as! Dictionary<String, Any>
            let dataObj = picture["data"] as! Dictionary<String,Any>

            var emailValue = result["email"] as! String?

            if emailValue == nil {
                emailValue = ""
            }
            let name = result["name"] as? String
            let id = result["id"] as? String
            let imageUrl = result["url"] as? String

            // Update data to firestore

        }
    })
}

我收到类似无法将类型“(_) -> ()”的值转换为预期参数类型的错误 'LoginManagerLoginResultBlock?'(又名 'Optional<(Optional, Optional) -> ()>')

如果我尝试解决这个问题,它会告诉我这里没有找到案例,下面是图片我想做的是获取一些用户信息并将其上传到 Cloud Firestore 任何帮助信息都会有帮助

试试这个解决方案,这对我有效。

@IBAction func btnFBClick(_ sender: UIButton)
{
    let fbLoginManager : LoginManager = LoginManager()
    fbLoginManager.logIn(permissions: ["email"], from: self)
    { (result, error) -> Void in
        if (error == nil){
            let fbloginresult : LoginManagerLoginResult = result!
            // if user cancel the login
            if (result?.isCancelled)!
            {
                return
            }
            if(fbloginresult.grantedPermissions.contains("email"))
            {
                self.getFBUserData()
                // fbLoginManager.logOut()
            }
        }
    }
}

func getFBUserData()
{

   if((AccessToken.current) != nil)
   {
      GraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler:
                { (connection, result, error) -> Void in
                    if (error == nil)
                    {
                        if let data = result as? NSDictionary
                        {
                            let firstName  = data.object(forKey: "first_name") as? String
                            let lastName  = data.object(forKey: "last_name") as? String
                            let name = data.object(forKey: "name") as? String

                           if let email = data.object(forKey: "email") as? String
                           {

                           }
                           else
                           {
                                self.view.makeToast("We are unable to access Facebook account details, please use other sign in methods.")
                           }
                        }
                    }
            })
        }
}