使用Firebase提供的API密钥无效

Has*_*ood 14 facebook ios firebase swift firebase-authentication

我正在使用Firebase Auth来允许用户使用Facebook注册.我已经从这里采取了所有步骤来实施注册,包括将GoogleService-Info.plist添加到我的项目中.

我获得了Facebook权限屏幕,但是当应用程序点击时

FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
Run Code Online (Sandbox Code Playgroud)

返回此错误:请求中提供了无效的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)
                    }
                }
            }

        }
    })
}
Run Code Online (Sandbox Code Playgroud)

Has*_*ood 34

解决了它,适用于将来需要解决方案的任何人.

有时,GoogleService-Info.plist中缺少API_KEY,需要添加.

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


小智 15

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

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

  • 再次下载它解决了我的问题...这很奇怪,因为我没有对我的项目进行任何更改. (2认同)