admin管理员组文章数量:1434907
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
2 Answers
Reset to default 4i 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.
版权声明:本文标题:javascript - firebase Certificate object must contain a string "private_key" property - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745596645a2665521.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论