我遇到了將消息發送到Firebase Cloud Messaging by Node應用程序的問題。在節點中發送FCM推送
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未授權的響應。我無法理解爲什麼我得到這個錯誤。我使用了正確的服務器密鑰。在我使用的策略中是否有語法錯誤或任何錯誤?
如果你的服務器的API密鑰有效你檢查?我今天遇到了同樣的問題,並且我的API密鑰在Fire Messaging網站中的Cloud Messaging下有所不同。所以我不得不再次更改API密鑰。 – GeorgeLBA
我糾正 我在火力點「添加火力地堡您的Android應用」 創建的Android應用程序的問題,我在複製谷歌,service.json API_KEY存在 昨天它的工作原理,但不是今天! 我解決了這個問題,通過「添加Firebase到您的網絡應用」中的cklick,我複製apiKey apiKey它不是在google-service.json中的api_key –
試試這個:https://github.com/emretekince/fcm-web -推 –