最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - firebase Certificate object must contain a string "private_key" property - Stack Overflow

matteradmin7PV0评论

I am using firebase cloud messaging with node.js. I just want to connect to firebase cloud messaging I get this error message:

/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.

this is my code:

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);
  });

and here is my google-services.json file. I downloaded it from firebase console. There is no key private_key property that is right, but I have downloaded the correct google-services.json. My Firebase-admin version is 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"
}

I am using firebase cloud messaging with node.js. I just want to connect to firebase cloud messaging I get this error message:

/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.

this is my code:

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);
  });

and here is my google-services.json file. I downloaded it from firebase console. There is no key private_key property that is right, but I have downloaded the correct google-services.json. My Firebase-admin version is 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"
}
Share Improve this question edited Jul 20, 2018 at 9:04 KENdi 7,7892 gold badges18 silver badges31 bronze badges asked Jul 20, 2018 at 0:09 ottootto 2,0638 gold badges42 silver badges69 bronze badges 1
  • 1 Have you enabled fcm service over there properly? – Dev Commented Jul 20, 2018 at 2:19
Add a ment  | 

2 Answers 2

Reset to default 4

i downloaded the wrong json file. Correct json file is in settings -> serviceaccounts -> and then generate key

According AppOptions interface you need also pass as a param insite initializeApp() method a property named projectId in the same level of credential property with the project id value.

Post a comment

comment list (0)

  1. No comments so far