请求中提供了无效的API密钥

时间:2017-01-29 01:36:02

标签: ios swift firebase firebase-authentication

我正在尝试创建我的第一个应用程序,不幸的是每个人都记得他们的第一段代码用一种新语言,不用说,这是一个麻烦的一半。现在,我正在使用下载的测试文件来了解使用swift实施Firebase的过程。目前,除了让应用程序记录电子邮件以及在将用户创建到数据库时传递时,我并不关心任何事情。

我对GoogleService-Info.plist进行了双重和三重检查,以确保存在正确的API密钥。在检查捆绑包ID和所有其他信息是否正确后,我已经多次下载了Google文件。该应用程序加载并运行,让我输入一个电子邮件和一个密码,一旦我按下按钮注册它就会抛出无效的API错误。 这就是我的podfile看起来像

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'FirebaseTutorial' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for FirebaseTutorial
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
end

这是注册的功能代码。

@IBAction func createAccountAction(_ sender: AnyObject) {

    if emailTextField.text == "" {
        let alertController = UIAlertController(title: "Error", message: "Please enter your email and password", preferredStyle: .alert)

        let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
        alertController.addAction(defaultAction)

        present(alertController, animated: true, completion: nil)

    } else {
        FIRAuth.auth()?.createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in

            if error == nil {
                print("You have successfully signed up")
                //Goes to the Setup page which lets the user take a photo for their profile picture and also chose a username

                let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
                self.present(vc!, animated: true, completion: nil)

            } else {
                let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)

                let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
                alertController.addAction(defaultAction)

                self.present(alertController, animated: true, completion: nil)
            }
        }
    }
}}

这是AppDelegate.swift中的代码

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FIRApp.configure()

    return true
}

如果我能提供其他任何帮助,请告诉我。我觉得非常绝望,每次google搜索和搜索都会让我创建一个帐户并提出这个问题。每个人都必须在某个地方开始吗?

0 个答案:

没有答案