简体   繁体   English

与 Firebase 安装服务器 API 通信时的 Android 错误

[英]Android Error when communicating with the Firebase Installations server API

I am getting an Error Message on App Startup Stating Logs like我在应用程序启动时收到一条错误消息,说明日志如

W/Firebase-Installations: Error when communicating with the Firebase Installations server API. HTTP response: [400 Bad Request: {
  "error": {
    "code": 400,
    "message": "API key not valid. Please pass a valid API key.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developers console",
            "url": "https://console.developers.google.com"
          }
        ]
      }
    ]
  }
}
]
2020-04-27 12:42:34.621 22226-23596/in.co.androidapp.g7 E/Firebase-Installations: Firebase Installations can not communicate with Firebase server APIs due to invalid configuration. Please update your Firebase initialization process and set valid Firebase options (API key, Project ID, Application ID) when initializing Firebase.

I got an email about a week earlier that I should update my google_services.json File, which I have done 4-5 times.大约一周前我收到一封电子邮件,我应该更新我的 google_services.json 文件,我已经更新了 4-5 次。 No Improvements.没有改进。 It had been working fine for around a year.它已经工作了大约一年。 Its been only 2-3 days since I am facing this issue in the app.自从我在应用程序中遇到此问题以来只有 2-3 天。

Subsequently, Firebase Cloud Messaging and other firebase services are not working.随后,Firebase Cloud Messaging 和其他 Firebase 服务无法正常工作。 I am not doing programmatic initialization (that is, using a FirebaseOptions object to provide these values), just the default initialization using FirebaseApp.initializeApp(this);我没有进行编程初始化(即,使用 FirebaseOptions 对象提供这些值),只是使用FirebaseApp.initializeApp(this);

I have tried https://github.com/firebase/firebase-android-sdk/blob/master/firebase-installations/API_KEY_RESTRICTIONS.md我试过https://github.com/firebase/firebase-android-sdk/blob/master/firebase-installations/API_KEY_RESTRICTIONS.md

Thanks in Advance.提前致谢。

I had this same issue.我有同样的问题。 I solved it by the following way.我通过以下方式解决了它。

go to app/build/generated/res/google-services/debug/values/values.xml go 到 app/build/generated/res/google-services/debug/values/values.xml

Here you can find your old API key.在这里您可以找到旧的 API 密钥。

Replace both google_api_key and google_crash_reporting_api_key values with the new one that you can find from the google-services.json file.将 google_api_key 和 google_crash_reporting_api_key 值替换为您可以从 google-services.json 文件中找到的新值。 it will be under api-key array.它将在 api-key 数组下。

Cheers!干杯!

If you have issues with your API key, you can create a new API key in the Cloud Console:如果您的 API 密钥有问题,您可以在 Cloud Console 中创建新的 API 密钥:

  • go to the Google Cloud Console go 到Google Cloud Console
  • choose the relevant project (ie the project you use for your application)选择相关项目(即您用于应用程序的项目)
  • open the menu and go to APIs & ServicesCredentials打开菜单和 go 到APIs & ServicesCredentials
  • on top of the page click on + CREATE CREDENTIALSAPI key在页面顶部单击+ CREATE CREDENTIALSAPI key
  • replace the API key in your application with the newly created API key用新创建的 API 密钥替换应用程序中的 API 密钥

In case you are using the google-services.json config file from your Firebase Console , you first have to delete or restrict the API key used in your current google-services.json in order to make Firebase update config file and use a new API key. In case you are using the google-services.json config file from your Firebase Console , you first have to delete or restrict the API key used in your current google-services.json in order to make Firebase update config file and use a new API钥匙。

  • Identify the API key in your google-services.json config file.在您的google-services.json配置文件中识别 API 密钥。
  • Confirm that the API key is creating the erroneous requests by checking its usage against the Firebase Installations API metrics page .通过对照Firebase 安装 API 指标页面检查其使用情况,确认 API 密钥正在创建错误请求。 The column Usage with this service of your API key should show a number greater than 0.您的 API 密钥的Usage with this service应显示大于 0 的数字。
  • Delete that API key by clicking the bin symbol or add Application restrictions to that API key by clicking the pencil symbol.通过单击 bin 符号删除该 API 键,或通过单击铅笔符号向该 API 键添加Application restrictions !!Warning!! !!警告!! Do not delete an API key that existing installations of your applications require for other Firebase services like Firebase Auth or Realtime-Database.不要删除 API 密钥,您的应用程序的现有安装需要其他 Firebase 服务(例如 Firebase Auth 或 Realtime-Database)。

Wait a couple of minutes for Google servers to update.等待几分钟让 Google 服务器更新。 The next download of your google-service.json config file should contain a new API key.下一次下载的google-service.json配置文件应该包含一个新的 API 密钥。

You can test your configuration with the following CURL command.您可以使用以下 CURL 命令测试您的配置。 What is the error you are getting?你得到什么错误 (Note: If you are seeing JSON data the request was and your configuration is successful) (注意:如果您看到 JSON 数据,则请求是并且您的配置成功)


Test if your configuration works with the following CURL command:测试您的配置是否适用于以下 CURL 命令:

api_key=<YOUR_API_KEY>;
project_identifier=<YOUR_PROJECT_ID>;
app_id=<YOUR_FIREBASE_APP_ID_EXAMPLE_1:12345678:android:00000aaaaaaaa>;

curl -H "content-type: application/json" -d "{appId: '$app_id', sdkVersion: 't:1'}" https://firebaseinstallations.googleapis.com/v1/projects/$project_identifier/installations/?key=$api_key;

Other relevant links regarding API keys and the Firebase Installations API :有关 API 密钥和Firebase 安装 API的其他相关链接:

Late but might be helpful to others.迟到但可能对其他人有帮助。

I tried everthing here, at last I got it working by making sure following steps,我在这里尝试了一切,最后我通过确保以下步骤使其正常工作,

Rule: App's SHA-1 should be registerd in Google Developer Console with the API keys used.规则:应使用 API 密钥在 Google Developer Console 中注册应用的 SHA-1。

  1. Look for the SHA-1 you are using (debug or release).查找您正在使用的 SHA-1(调试或发布)。 You can do it by going to android studio > Gradle form side bar > Tasks > android > signingReport.您可以通过转到 android 工作室 > Gradle 表单侧栏 > 任务 > android > 签名报告来完成。 Double click on it to run.双击它运行。 Once it runs, you will be able to find out SHA-1 for your variant.运行后,您将能够为您的变体找出 SHA-1。 (In my case, I was trying to make it run for release variant). (在我的情况下,我试图让它为发布变体运行)。 Keep that SHA-1 aside we will check for its existance on Google Developers Console.将 SHA-1 放在一边,我们将在 Google Developers Console 上检查它是否存在。

  2. Now head over to https://console.cloud.google.com/apis/credentials , In your selected project > Credentials, Find API key that is used, Click on it to go into details, Find Restrict usage to your Android apps , see if the SHA-1 is registed there along with your package name. Now head over to https://console.cloud.google.com/apis/credentials , In your selected project > Credentials, Find API key that is used, Click on it to go into details, Find Restrict usage to your Android apps ,查看 SHA-1 是否与您的 package 名称一起注册。

If you do not find the same SHA-1 that you had in your project, then you can click on Add an Item to add the app.如果您没有在项目中找到相同的 SHA-1,则可以单击Add an Item以添加应用程序。 Pass package name and SHA-1 and submit.通过 package 名称和 SHA-1 并提交。

Try again to connect firebase APIs after 5-10 mins. 5-10 分钟后再次尝试连接 firebase API。

在此处输入图像描述

I encountered with this error when initializing new app so it may not solve your issue since you say your app is existing but I hope it helps.我在初始化新应用程序时遇到了这个错误,所以它可能无法解决你的问题,因为你说你的应用程序已经存在,但我希望它有所帮助。

I've created new SHA Key for SHA-1 fingerprint of keystore certificate (both for debug and signing! only signing didn't work)为密钥库证书的 SHA-1 指纹创建了新的 SHA 密钥(用于调试和签名!只有签名不起作用)

and I've added them into my firebase settings (below my package name careful if you have multiple).我已将它们添加到我的 firebase 设置中(如果您有多个,请在我的 package 名称下方小心)。 Now it works for me.现在它对我有用。

It turned out that the issue was with the version of firebase-messaging for me, using this version in app gradle got rid of the error:事实证明,问题出在我的 firebase-messaging 版本上,在应用程序 gradle 中使用此版本消除了错误:

implementation "com.google.firebase:firebase-messaging:20.1.0"

This error could happen if you include in gradle some firebase modules that not configured properly (analytics, storage, messaging etc.)如果您在 gradle 中包含一些未正确配置的 firebase 模块(分析、存储、消息传递等),则可能会发生此错误

I encountered the same issue, click on the link provided:我遇到了同样的问题,点击提供的链接:

"links": [
          {
            "description": "Google developers console",
            "url": "https://console.developers.google.com"
          }

From there on, Go to the 'credentials' menu.从那里开始,Go 到“凭证”菜单。

Confirm in your google-services.json file the API key being used.在您的 google-services.json 文件中确认正在使用的 API 密钥。

Go back to the google portal and look for that key under API keys. Go 返回谷歌门户并在 API 密钥下查找该密钥。 Once you find it, click to edit and when editing, add your project's package name and SHA-1 certificate key.找到它后,单击以进行编辑,并在编辑时添加项目的 package 名称和 SHA-1 证书密钥。

Save and wait for 5 mins, the error should be gone.保存并等待5分钟,错误应该消失了。

I had the same issue.我遇到过同样的问题。 Please find the following steps i followed to resolve this.请找到我遵循的以下步骤来解决此问题。

  1. Navigate to the google project and make sure your app sha1 key is configured properly.导航到 google 项目并确保您的应用程序 sha1 密钥配置正确。
  2. Download the google-services.json file from the project and make sure it is same as the one exists in the android project从项目中下载 google-services.json 文件并确保它与 android 项目中存在的文件相同
  3. Clean the project to remove all build configurations generated previously.清理项目以删除之前生成的所有构建配置。
  4. Build the app构建应用程序

Just Register your app in the Firebase console again.只需再次在Firebase控制台中注册您的应用程序。 and get the googl-service.json file and replace it with old.并获取googl-service.json文件并将其替换为旧文件。 it will be solve会解决的

To fix this error read this file using CMD or Windows Explorer要修复此错误,请使用 CMD 或 Windows Explorer 读取此文件

PS C:\Users\Any> keytool -keystore C:\Users\Any\.android\debug.keystore -list -v PS C:\Users\Any> keytool -keystore C:\Users\Any\.android\debug.keystore -list -v

Enter keystore password:输入密钥库密码:

Use 'KeyStore Explorer' from https://keystore-explorer.org/downloads.html使用https://keystore-explorer.org/downloads.html 中的“KeyStore Explorer”

& paste it here: https://console.developers.google.com/apis/credentials/key/并在此处粘贴: https://console.developers.google.com/apis/credentials/key/

If you are facing this issue in the Flutter app then go to your project directory and delete the build folder.如果您在 Flutter 应用程序中遇到此问题,则将 go 到您的项目目录并删除构建文件夹。 Hopefully, it will work.希望它会奏效。

Here's what made that error go away for my app: I deleted the Project .gradle folder, the Project build folder and the app build folder, all at once.这是导致我的应用程序出现错误 go 的原因:我一次删除了 Project .gradle文件夹、Project build文件夹和 app build文件夹。 I then re-installed the app, and no more Firebase Installations server API error!然后我重新安装了应用程序,不再出现 Firebase 安装服务器 API 错误!

This problem face me and I fixed by go to Google cloud platform and credentials and do API for firebase with Application restrictions or API restrictions as you used. This problem face me and I fixed by go to Google cloud platform and credentials and do API for firebase with Application restrictions or API restrictions as you used.

If you have changed your API Key on https://console.cloud.google.com or you have restricted it you gotta follow these steps:如果您更改了https://console.cloud.google.com上的 API 密钥,或者您已限制它,您必须按照以下步骤操作:

  1. Make sure that your new key is into google-service.json (download from firebase console).确保您的新密钥进入google-service.json (从 firebase 控制台下载)。

  2. Open the google-service.json, find api_keys and leave just the current_key that belongs to every environment(dev or prod).打开 google-service.json,找到api_keys并只留下属于每个环境(dev 或 prod)的current_key

  3. Go to project/app and delete the folder build . Go 到project/app并删除文件夹build

Inside Google API's & Service Credentials > Android key (auto created by Firebase) > API Restrictions Google API 和服务凭证内部 > Android 密钥(由 Firebase 自动创建) > API 限制

Select All services and save. Select 所有服务并保存。 After 5-10 minute you can check. 5-10分钟后就可以检查了。

This is mainly happened by your outdated google-services.json file.这主要是由您过时的 google-services.json 文件引起的。 because sometime you may enable some extra services in firebase has changed the entire structure of that file.因为有时您可能会在 firebase 中启用一些额外的服务,从而改变了该文件的整个结构。 so go to your firebase console -> project settings -> download google-services.json and replace it所以转到你的firebase console -> project settings -> download google-services.json并替换它

then rebuild your app.然后重建你的应用程序。 Now you check your firebase has error现在你检查你的 firebase 有错误

I had this issue in Iran.我在伊朗遇到过这个问题。 after running a VPN my app was connected to firebase.运行 VPN 后,我的应用程序已连接到 firebase。

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

相关问题 与 Firebase 安装服务器通信时出错 API - 403 Forbidden - Error when communicating with the Firebase Installations server API - 403 Forbidden 尝试查询附加组件的安装时出错 - Getting an error when trying to query the installations of add-on Xamarin.iOS Firebase 错误代码 8003“无法获取安装令牌” - Xamarin.iOS Firebase error code 8003 "Failed to get installations token" Sendy“与 Amazon SNS 通信时出错 API:执行此请求时出现问题” - Sendy 'Error communicating with Amazon SNS API: There was a problem executing this request' 在 Android 上登录 Facebook/Firebase 时出错 - Error When Logging on Facebook/Firebase on Android 向 curl 和 api v1 主题发送 firebase 通知时出错 - Error when sending firebase notification to topics with curl and api v1 错误:尝试将数据发布到 Firebase 服务器时出现 MISSING_EMAIL - Error : MISSING_EMAIL when trying to post data to a Firebase Server 使用 firebase unity sdk firestore package 时 android 设备出错 - Error on android device when using firebase unity sdk firestore package 使用 Firebase 实时数据库和 Android (Java) 时,Firebase API 的异步行为出现问题 - Problem with the asynchronous behavior of Firebase API when using Firebase Realtime Database and Android (Java) Firebase 不工作 com.google.firebase.installations.FirebaseInstallationsException - Firebase not working com.google.firebase.installations.FirebaseInstallationsException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM