Auth in firebase with facebookSDK


#1

Всем доброго времени суток, ребята если кто знает подскажите плз, регистрация через facebook возвращает пустую строку в поле email в firebase, как решить вопрос??


#2
func facebookAuth() {
    let fbLoginManager: LoginManager = LoginManager()

    fbLoginManager.logIn(permissions: ["email"], from: self, handler: { (result, error) -> Void in
        if error == nil {
            let fbloginresult: LoginManagerLoginResult = result!

            if fbloginresult.isCancelled {
                // Show cancel alert
            } else if fbloginresult.grantedPermissions.contains("email") {
                self.handleFBResponse()
            }
        }
    })
}

func handleFBResponse() {
    let graphRequest: GraphRequest = GraphRequest(graphPath: "me", parameters: ["fields": "id,first_name,last_name,email"])
    graphRequest.start(completionHandler: { (_, result, error) -> Void in
        if error != nil {
            // Process error
        } else {
            let resultDic = result as! NSDictionary

            if resultDic.value(forKey: "first_name") != nil {
                self.firstName = resultDic.value(forKey: "first_name") as! String?
            }

            if resultDic.value(forKey: "last_name") != nil {
                self.lastName = resultDic.value(forKey: "last_name") as! String?
            }

            if resultDic.value(forKey: "email") != nil {
                self.email = resultDic.value(forKey: "email") as! String?
            }

            self.facebookCredential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current?.tokenString ?? "")

            //firebase auth with facebookCredential 
        }
    })
}

У меня в одном проекте работает так.