【问题标题】:firebase Certificate object must contain a string "private_key" propertyfirebase 证书对象必须包含字符串“private_key”属性
【发布时间】:2018-12-28 05:23:35
【问题描述】:

我正在使用带有 node.js 的 firebase 云消息传递。我只想连接到 Firebase 云消息传递 我收到此错误消息:

/home/t/ws/js/webserver/blitzer/node_modules/firebase-admin/lib/auth/credential.js:119
            throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_CREDENTIAL, errorMessage);
            ^

Error: Certificate object must contain a string "private_key" property.

这是我的代码:

import * as admin from 'firebase-admin'
import serviceAccount from  './google-services.json'
const registrationToken = 'fMaw-YgWgwY:APA91bEwv7Z_FHPx0kCuiM6_Ji004_d_K5WQh9PMH1IgshLb_Lqq7zhicKdg6lFO5dl0FY3im5r0jgMZrWNbZIXpPL4k1JC22hT5fUY5h5B3RVXjgRCBQI-l9cNxBRVZP-cnJtyYbqMKqmwvGD8fg3ae8QQjAkRe0w'

var message = {
    data: {
      score: '850',
      time: '2:45'
    },
    token: registrationToken
  };
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
});


admin.messaging().send(message)
  .then((response) => {
    // Response is a message ID string.
    console.log('Successfully sent message:', response);
  })
  .catch((error) => {
    console.log('Error sending message:', error);
  });

这是我的 google-services.json 文件。我从firebase控制台下载了它。没有正确的密钥 private_key 属性,但我已经下载了正确的 google-services.json。我的 Firebase-admin 版本是 5.13.0

{
  "project_info": {
    "project_number": "x",
    "firebase_url": "x",
    "project_id": "x",
    "storage_bucket": "x"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "x",
        "android_client_info": {
          "package_name": "x"
        }
      },
      "oauth_client": [
        {
          "client_id": "x",
          "client_type": x
        }
      ],
      "api_key": [
        {
          "current_key": "x"
        }
      ],
      "services": {
        "analytics_service": {
          "status": x
        },
        "appinvite_service": {
          "status": x,
          "other_platform_oauth_client": []
        },
        "ads_service": {
          "status": x
        }
      }
    }
  ],
  "configuration_version": "x"
}

【问题讨论】:

  • 你那边的fcm服务开通了吗?

标签: javascript android node.js firebase firebase-cloud-messaging


【解决方案1】:

我下载了错误的 json 文件。正确的json文件在settings -> serviceaccounts -> 然后生成key

【讨论】:

    猜你喜欢
    • 2018-01-03
    • 2021-10-02
    • 2017-11-15
    • 2022-08-11
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-27
    相关资源
    最近更新 更多