繁体   English   中英

firebase 证书 object 必须包含字符串“private_key”属性

[英]firebase Certificate object must contain a string "private_key" property

我正在使用 firebase 云消息传递与 node.js。 我只想连接到 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 管理员版本是 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"
}

我下载了错误的json文件。 正确的json文件位于设置-> serviceaccounts->然后生成密钥

根据AppOptions 接口,您还需要将一个名为projectId的属性作为参数传递给 insite initializeApp()方法,该属性与项目 id 值位于同一级别的credential属性中。

暂无
暂无

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

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