HTTP.post para o FCM Server não está funcionando
Estou usando o Ionic 2 comMódulo nativo HTTP para fazer uma solicitação de postagem ao servidor FCM para receber notificações por push. O código que estou usando é:
HTTP.post(
"https://fcm.googleapis.com/fcm/send",
{
"notification": {
"title": "Notification title",
"body": "Notification body",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "fcm_push_icon"
},
"data": {
"hello": "This is a Firebase Cloud Messagin hbhj g Device Gr new v Message!",
},
"to": "device token",
},
{
Authorization: {
key: "AUTHORIZATION KEY HERE"
}
})
Está me dando um erro:
Unimplemented console API: Unhandled Promise rejection:
Unimplemented console API: Error: Uncaught (in promise): [object Object]
Eu tentei o pedido de postagem com o Postman, ele funciona perfeitamente bem, fornecendo notificações push.
O código com o Postman é:
POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Content-Type: application/json
Authorization: key=Authorisation Key
Cache-Control: no-cache
Postman-Token: 446e253b-179a-d19b-21ea-82d9bb5d4e1c
{
"to": "Device Token",
"data": {
"hello": "This is a Firebase Cloud Messagin hbhj g Device Gr new v Message!",
}
"notification":{
"title":"Notification title",
"body":"Notification body",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
}
Questões:
Não consigo adicionarcontent-type
para o cabeçalho na solicitação de postagem HTTP, mas funciona com o carteiro.
Se eu tentar adicionar umfunction(response) {
para obter a resposta do servidor, isso me dá um erro. A documentação para o mesmo está emhttps://github.com/wymsee/cordova-HTTP