Facebook登录和Firebase快速问题

问题描述 投票:0回答:1

我已在YouTube上遵循了这个简短而快速的教程,将Facebook登录名和firebase添加到我的应用中:https://www.youtube.com/watch?v=2CTnZxYI3oM

但是以某种方式我得到了您可以在图片中看到的错误:

enter image description here

这是我的书面代码:

class SigninViewController: UIViewController, LoginButtonDelegate {



@IBOutlet weak var fbButton: FBLoginButton!

override func viewDidLoad() {
    super.viewDidLoad()

    fbButton.delegate = self
    fbButton.readPermissions = ["email"] // to read the user email ID
}
func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult!, error: Error!) {
    if error == nil
    {
        let credential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current().tokenString)
        Auth.auth().signInAndRetrieveData(with: credential) { (authResult, error) in
          if let error = error {
            print(error.localizedDescription)
            return
          }
            print(authResult?.user.email)
        }
    }
    else
    {
        print((error.localizedDescription))
    }
}

func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
    print("user logged out")
   }
}

任何想法?给你加油!

xcode firebase swift5 facebook-sdk-4.0
1个回答
0
投票
import UIKit
import FBSDKLoginKit
import Firebase

 class LoginViewController: UIViewController,UIScrollViewDelegate {


//MARK: VIEW LIFE CYCLES
override func viewDidLoad() {
    super.viewDidLoad()

}


override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)


}

    //MARK: FACEBOOK LOGIN
  //============
     @IBAction func btnFBClick(_ sender: UIButton)
   {
//calls the facebook login function that is defined in the fbMuser   class
loginFaceBookuser()
    self.dismiss(animated: true, completion: nil)

//MARK: facebook Login Function
//FACEBOOKElOGINFUNCTIONS
func loginFaceBookuser(){
    let fbLoginManager : LoginManager = LoginManager()
        fbLoginManager.logIn(permissions: ["email"], from: LoginViewController() )
    { (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()
                //MARK: perform navigation segue to profile page
                                   let homeView = self.storyboard?.instantiateViewController(withIdentifier: "profileviewcontroller") as! secondProfileTableViewController
                                   self.navigationController?.pushViewController(homeView, animated: true)
                // fbLoginManager.logOut()

            }
        }
    }
}


    //this function helps me get the user data from facebook then i then i store the all the data into firebase under my User collection
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
                                let id = data.object(forKey: "id") as? String
                                //what we need to do next is make a document path in the users collection for full address and purchase itemids
                               if let email = data.object(forKey: "email") as? String
                               {
                                //MARK: TO DO IF THE USERS ALREADY EXIST IN THE FIRESTORE SERVER  DO NOT PERFORM SET DATA IT WILL OVERWRITE PREVIOUS DATA! NEED TO WRITE CODE TO DETECT THIS
                                FirebaseReferece(.User).document(id!).setData(data as! [String : Any]) //saves all the information under user the document id is id
                                saveit()

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

           }





 }//MARK: END OF CLASS
© www.soinside.com 2019 - 2024. All rights reserved.