在节点中发送FCM推送 [英] Sending FCM push in Node

查看:77
本文介绍了在节点中发送FCM推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过Node应用程序向Firebase Cloud Messaging发送消息.

I've got problem with sending message to Firebase Cloud Messaging by Node application.

 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.我无法理解为什么会收到此错误.我使用了正确的服务器密钥.我使用的策略中是否存在语法错误或任何错误.

When I call the above code, it gives me response as 401 Unauthorized. I am not able to understand why I am getting this error. I have used proper server key. Is there any syntax error or anything wrong in the strategy used by me.

推荐答案

您需要使用Cloud Messaging密钥,该密钥与其他API密钥不同.

You need to use the Cloud Messaging key, is different from the other API keys.

要获取密钥,请访问 https://console.firebase .google.com/project/:project-name/settings/cloudmessaging (用您的项目名称替换:project_name)

To get the key go to https://console.firebase.google.com/project/:project-name/settings/cloudmessaging (replace :project_name with your project name)

这篇关于在节点中发送FCM推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆