I am trying to login through Facebook, collect some data over OAuth and then login to Firebase using the credential. I am however encountering an issue (please see logs below).
CODE EXAMPLE
@objc func signInWFB() {
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logIn(withReadPermissions: ["email","user_birthday","user_gender"], from: self) { (result, error) -> Void in
if (error == nil) {
let fbloginresult : FBSDKLoginManagerLoginResult = result!
if (result?.isCancelled)! {
print(result ?? FBSDKLoginManagerLoginResult())
} else if(fbloginresult.grantedPermissions.contains("email")) {
if((FBSDKAccessToken.current()) != nil) {
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email, birthday, gender"]).start( completionHandler: { (connection, result, error) -> Void in
if (error == nil) {
//everything works print the user data
print(result ?? AnyObject.self)
if let d = result as? [String:Any] {
// ALL GOOD UP TO HERE
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current()!.tokenString)
Auth.auth().signIn(with: credential) { (authResult, error) in
if let error = error {
print(error) // ERROR HERE
return
}
// ...
}
}
}
})
}
}
}
}
}
LOGS
Error Domain=FIRAuthErrorDomain Code=17004 "Unsuccessful debug_token response from Facebook: {"error":{"message":"(#100) The App_id in the input_token did not match the Viewing App","type":"OAuthException","code":100,"fbtrace_id":"BwV3jZweRqo"}}" UserInfo={NSLocalizedDescription=Unsuccessful debug_token response from Facebook: {"error":{"message":"(#100) The App_id in the input_token did not match the Viewing App","type":"OAuthException","code":100,"fbtrace_id":"BwV3jZweRqo"}}, error_name=ERROR_INVALID_CREDENTIAL}
WHAT I'VE TRIED
This was ridiculously hard to find. I had to go to Firebase > Authentication > Sign-in Method > Facebook and change the fields in there to match those on Facebook developer. For some inexplicable reason they were different...
If you're using expo with React Native, this might save you some time. Because at the moment, Facebook Login on iOS can only work with standalone apps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With