【问题标题】:How to integrate two or more google-services.json file together for different google FCM service in same project如何为同一项目中的不同 google FCM 服务集成两个或多个 google-services.json 文件
【发布时间】:2017-05-25 09:36:22
【问题描述】:

我正在制作一个项目,我想在其中集成不同的 FCM google-service.json,如何在同一个文件中集成不同的项目密钥我尝试了 2 个类似但不工作的项目,我们需要添加在我们的项目中。

    {
          "project_info": {
            "project_number": "60554696754247",
            "firebase_url": "https://project-1fca7.firebaseio.com",
            "project_id": "project-1fca7",
            "storage_bucket": "project-1fca7.appspot.com"
          },
          "client": [
            {
              "client_info": {
                "mobilesdk_app_id": "xxxxxxxxxxxxx",
                "android_client_info": {
                  "package_name": "com.company.project1"
                }
              },
              "oauth_client": [
                {
                  "client_id": "xxxxxxxxxxxxxxxx",
                  "client_type": 3
                }
              ],
              "api_key": [
                {
                  "current_key": ""
                }
              ],
              "services": {
                "analytics_service": {
                  "status": 1
                },
                "appinvite_service": {
                  "status": 1,
                  "other_platform_oauth_client": []
                },
                "ads_service": {
                  "status": 2
                }
              }
            }
          ],
          "project_info": {
            "project_number": "13052496681",
            "firebase_url": "https://project-2ebf8.firebaseio.com",
            "project_id": "project-2ebf8",
            "storage_bucket": "project-2ebf8.appspot.com"
          },
          "client": [
            {
              "client_info": {
                "mobilesdk_app_id": "xxxxxxxxxxxxxxx",
                "android_client_info": {
                  "package_name": "com.company.project2"
                }
              },
              "oauth_client": [
                {
                  "client_id": "xxxxxxxxxxxxxx",
                  "client_type": 3
                }
              ],
              "api_key": [
                {
                  "current_key": "xxxxxxxxxxxxxxxx"
                }
              ],
              "services": {
                "analytics_service": {
                  "status": 1
                },
                "appinvite_service": {
                  "status": 1,
                  "other_platform_oauth_client": []
                },
                "ads_service": {
                  "status": 2
                }
              }
            }
          ],

          "configuration_version": "1"
        }

【问题讨论】:

  • 一般来说,强烈不建议修改 google-services.json 文件。你为什么要这样做?

标签: json firebase firebase-cloud-messaging google-play-services


【解决方案1】:

尚不清楚您的用例到底是什么,但值得注意的是,使用 google-services.json 文件是完全可选的,在您的情况下,您可能希望跳过它并手动配置您的应用程序。

documentation here 解释了插件如何处理 JSON 文件。

基本上,该插件会创建一个如下所示的strings.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <! -- Present in all applications -->
    <string name="google_app_id" translatable="false">1:1035469437089:android:73a4fb8297b2cd4f</string>

    <! -- Present in applications with the appropriate services configured -->
    <string name="gcm_defaultSenderId" translatable="false">1035469437089</string>
    <string name="default_web_client_id" translatable="false">337894902146-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com</string>
    <string name="ga_trackingId" translatable="false">UA-65557217-3</string>
    <string name="firebase_database_url" translatable="false">https://example-url.firebaseio.com</string>
    <string name="google_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
    <string name="google_crash_reporting_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>

</resources>

由于您在谈论 FCM,因此相关部分是 google_app_idgcm_defaultSenderIdgoogle_api_key。如果您在应用程序中使用这些名称创建字符串,Firebase 将正确自动初始化。

如果您想使用多个应用程序,如您所说,您需要手动初始化FirebaseApp,如下所示:

FirebaseApp customApp = FirebaseApp.initializeApp(this, 
       new FirebaseOptions.Builder()
           .setApplicationId(...)
           .setApiKey(...)
           .setGcmSenderId(...)
           .build(), 
       "custom-app-name");

【讨论】:

猜你喜欢
  • 2016-05-02
  • 2017-03-08
  • 1970-01-01
  • 2017-06-24
  • 1970-01-01
  • 1970-01-01
  • 2022-08-15
  • 1970-01-01
  • 2013-05-28
相关资源
最近更新 更多