Firebase 3.x - Facebook Login

前端 未结 1 1854
误落风尘
误落风尘 2021-01-07 13:21

InFirebase 2.5.1, I used to do this, and it was working:

@IBAction func facebookLoginDidTouch(sender: AnyObject) {

   let facebookLogin = FBSDK         


        
相关标签:
1条回答
  • 2021-01-07 13:56

    After you successfully login with facebook and get user data back ... you have to add firebase authentication stuff like

     @IBAction func facebookLoginDidTouch(sender: AnyObject) {
    
       let facebookLogin = FBSDKLoginManager() 
    
       facebookLogin.logInWithReadPermissions(["public_profile", "email"], fromViewController: self, handler: {
        (facebookResult, facebookError) -> Void in
            if facebookError != nil {
                print("Facebook login failed. Error \(facebookError)")
            } else if facebookResult.isCancelled {
                print("Facebook login was cancelled.")
            } else {
                // your firebase authentication stuff..
    
                let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
    
                FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
                if error != nil {
                      print("Login failed. \(error)")
                } else {
                     print("Logged in!")
    
                }
              })
            }
       })
    }
    
    0 讨论(0)
提交回复
热议问题