gpt4 book ai didi

node.js - 在 Node 中发送 FCM 推送

转载 作者:搜寻专家 更新时间:2023-10-31 23:59:46 25 4
gpt4 key购买 nike

我在通过 Node 应用程序向 Firebase Cloud Messaging 发送消息时遇到问题。

 request({
url: 'https://fcm.googleapis.com/fcm/send',
method: 'POST',
headers: {
'Content-Type' :' application/json',
'Authorization': 'key=AIzaSyAF9cvEThRo3ZlWCLuSU5k6W9kk0uumkLM',
'project_id': '83933810320'
},
body: JSON.stringify(
{ "data": {'notification': notification, _id: _id, action: action},
"registration_ids" : registration_ids,
"content_available": true,
}
)
}, function(error, response, body) {
if (error) {
console.error(error, response, body);
}
else if (response.statusCode >= 400) {
console.error('HTTP Error: '+response.statusCode+' - '+response.statusMessage+'\n'+body);
}
else {
console.log(response);
}
});

当我调用上面的代码时,它给我的响应是 401 Unauthorized。我无法理解为什么会出现此错误。我使用了正确的服务器 key 。我使用的策略是否有任何语法错误或任何错误。

最佳答案

您需要使用 Cloud Messaging key ,这与其他 API key 不同。

要获取 key ,请转到 https://console.firebase.google.com/project/:project-name/settings/cloudmessaging (将 :project_name 替换为您的项目名称)

关于node.js - 在 Node 中发送 FCM 推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39129697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com