Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid API Key supplied using Firebase

I'm using Firebase Auth to allow users to sign up using Facebook. I have taken all the steps from here to implement sign up including adding GoogleService-Info.plist to my project.

I get the Facebook permission screen all fine but when the app hits

FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in

this error is returned: An invalid API Key was supplied in the request.

Can anyone help me with this please?

Thanks

Here is my function code to log in using Facebook.

@IBAction func signUpWithFacebook() {

    let fbLogin = FBSDKLoginManager()

    fbLogin.logInWithReadPermissions(["email"], fromViewController:self,  handler: {
        (result, error) -> Void in

        if ((error) != nil) {
            print("Process error")
        } else if (result.isCancelled) {
            print("Cancelled");
        } else {
            print("Logged in");

            let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
            let credential = FIRFacebookAuthProvider.credentialWithAccessToken(accessToken)
            print(FBSDKAccessToken.currentAccessToken().tokenString)

            FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
                // ...
                if let user = user{
                    print(user.displayName)
                }
                else{

                    if let error = error {
                        print(error.localizedDescription)
                    }
                }
            }

        }
    })
}
like image 345
Hassan Mahmood Avatar asked May 25 '16 11:05

Hassan Mahmood


People also ask

How do I fix Invalid API key Firebase?

Make sure you've got the API keys set correctly in your Google Developer Console for your Firebase project. Show activity on this post. There are two different configurations for release mode and test mode. make sure that you use the API key which is related to each.

What is API key in FCM?

Summary: Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets users reliably send messages at no cost. The API key allows to send notification messages or data messages to all users of a specific app.


2 Answers

Solved it, for anyone that needs the solution in the future.

Sometimes API_KEY is missing from the GoogleService-Info.plist, this needs to be added.

The API Key can be found from Google API Console https://console.developers.google.com/

like image 186
Hassan Mahmood Avatar answered Sep 21 '22 13:09

Hassan Mahmood


You can solve this by Downloading again the "GoogleService-Info.plist" file, under the Project Setting section on Firebase Console.

Ensure that the API_KEY is set on the new "GoogleService-Info.plist".

like image 29
Ruben Castillo Avatar answered Sep 24 '22 13:09

Ruben Castillo