Invalid API Key supplied using Firebase

杀马特。学长 韩版系。学妹 提交于 2019-12-10 01:45:43

问题


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)
                    }
                }
            }

        }
    })
}

回答1:


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/




回答2:


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".



来源:https://stackoverflow.com/questions/37436352/invalid-api-key-supplied-using-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!