与Firebase安装服务器API通信时出现Android错误 [英] Android Error when communicating with the Firebase Installations server API

查看:89
本文介绍了与Firebase安装服务器API通信时出现Android错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在App Startup上收到一条错误消息,指出类似这样的日志

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.

大约一周前,我收到一封电子邮件,我应该更新google_services.json文件,该文件已经执行了4-5次.没有改善.它已经运行了大约一年了.自从我在应用程序中遇到此问题以来,只有2-3天了.

I got an email about a week earlier that I should update my google_services.json File, which I have done 4-5 times. 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.

随后,Firebase Cloud Messaging和其他Firebase服务无法正常工作.我不是在进行程序初始化(即使用FirebaseOptions对象提供这些值),而只是在使用 FirebaseApp.initializeApp(this);

Subsequently, Firebase Cloud Messaging and other firebase services are not working. I am not doing programmatic initialization (that is, using a FirebaseOptions object to provide these values), just the default initialization using FirebaseApp.initializeApp(this);

我尝试了 https://github.com/firebase/firebase-android-sdk/blob/master/firebase-installations/API_KEY_RESTRICTIONS.md

预先感谢.

推荐答案

如果API密钥存在问题,则可以在Cloud Console中创建新的API密钥:

If you have issues with your API key, you can create a new API key in the Cloud Console:

  • 转到 Google云控制台
  • 选择相关项目(即您用于应用程序的项目)
  • 打开菜单,然后转到 APIs&服务凭据
  • 在页面顶部单击 + CREATE CREDENTIALS API密钥
  • 用新创建的API密钥替换应用程序中的API密钥

如果您正在使用 Firebase中的 google-services.json 配置文件控制台,您首先必须删除或限制当前 google-services.json 中使用的API密钥,以使Firebase更新配置文件并使用新的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.

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

请等待几分钟,以更新Google服务器.您的 google-service.json 配置文件的下一次下载应包含新的API密钥.

Wait a couple of minutes for Google servers to update. The next download of your google-service.json config file should contain a new API key.

您可以使用以下CURL命令测试您的配置.您得到的是什么错误?(注意:如果您看到的是JSON数据,则请求成功,并且您的配置成功)

You can test your configuration with the following CURL command. What is the error you are getting? (Note: If you are seeing JSON data the request was and your configuration is successful)

测试您的配置是否适用于以下CURL命令:

Test if your configuration works with the following CURL command:

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;


有关API密钥和 Firebase安装API :

这篇关于与Firebase安装服务器API通信时出现Android错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆