简体   繁体   English

Firebase 无效的 API 密钥

[英]Firebase Invalid API key

I have an android project which I want to expand with Firebase.我有一个 android 项目,我想用 Firebase 扩展它。 Currently I've got an error logging when I want to test a crash with a log message.目前,当我想用​​日志消息测试崩溃时,我有一个错误日志记录。

Server did not receive report: Origin Error message: API key not valid. Please pass a valid API key.

What can I do to fix this?我能做些什么来解决这个问题? I've copied the google-services.json file to my project from the console.我已将 google-services.json 文件从控制台复制到我的项目中。

Got the same error in my Angular project.在我的 Angular 项目中遇到了同样的错误。 I know the question is for android but this is the question that pops up when I searched the error for angular so hopefully, it would help another person in the near future.我知道这个问题是针对 android 的,但这是当我搜索 angular 错误时弹出的问题,所以希望它会在不久的将来帮助另一个人。 Make sure you're importing the right variable.确保您正在导入正确的变量。 In the app.module.ts file:在 app.module.ts 文件中:

import { FIREBASE } from 'src/environments/firebase';

imports: [
    AngularFireModule.initializeApp(FIREBASE.firebase)
  ],

firebase.ts (environment file) fill with your config info from firebase. firebase.ts(环境文件)填充来自 firebase 的配置信息。

export const FIREBASE = {
  production: false,
  firebase: {
    apiKey: "",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: "",
  measurementId: ""
  }
};

So make sure you're importing the right variable.因此,请确保您导入了正确的变量。 Took me some time to figure out.我花了一些时间才弄清楚。 Happy coding!快乐编码!

确保在Google Developer Console 中为 Firebase 项目正确设置了 API 密钥。

There are two different configurations for release mode and test mode.发布模式和测试模式有两种不同的配置。 make sure that you use the API key which is related to each.确保您使用与每个相关的 API 密钥。 In the angular there are two environment files.在 angular 中有两个环境文件。 environment.prod.ts which is for production and environment.ts which is for testing. environment.prod.ts用于生产, environment.ts用于测试。 make sure that the api key in these files are correct.确保这些文件中的api 密钥是正确的。

晚安,我解决了这个问题


    npm i firebase --save

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM