使用 Firebase 提供的 API 密钥无效

Invalid API Key supplied using Firebase

我正在使用 Firebase Auth 来允许用户使用 Facebook 进行注册。我已从此处开始执行所有步骤来实施注册,包括将 GoogleService-Info.plist 添加到我的项目中。

我在 Facebook 权限屏幕上一切正常,但是当应用程序点击时

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

返回此错误:请求中提供了无效的 API 密钥。

谁能帮我解决这个问题?

谢谢

这是我使用 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)
                    }
                }
            }

        }
    })
}

已解决,以供日后需要解决方案的任何人使用。

有时 API_KEY 在 GoogleService-Info.plist 中丢失,这需要添加。

可以从 Google API 控制台找到 API 密钥 https://console.developers.google.com/

您可以通过在 Firebase 控制台的“项目设置”部分下再次下载 "GoogleService-Info.plist" 文件来解决此问题。

确保在新 "GoogleService-Info.plist" 上设置 API_KEY。