我正在使用带有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"
}
答案 0 :(得分:1)
我下载了错误的json文件。正确的json文件位于设置-> serviceaccounts->中,然后生成密钥