【问题标题】:Firebase notification can't create device group through HTTP.postFirebase 通知无法通过 HTTP.post 创建设备组
【发布时间】:2019-02-26 08:15:21
【问题描述】:

我正在尝试从 NodeJS 后端按照文档 (https://firebase.google.com/docs/cloud-messaging/js/device-group) 中的说明创建设备组,但我做不到,我总是遇到 400 错误

有人知道我做错了什么吗?

const httpRequest = require('request');

const options = {
    url: 'https://fcm.googleapis.com/fcm/notification',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'key=AAA...vR',
        'project_id': '76...8'
    },
    body: JSON.stringify({
        operation: 'create',
        notification_key_name: 'my-unique-key-name',
        registration_ids: ['token1', 'token2']
    })
};

    httpRequest(options, (error, response, body) => {
    if (!error && response.statusCode === 200) {
        resolve(Converter.parseJSON(body));
    } else {
        reject(error);
    }
});

提前感谢任何提示或帮助!

【问题讨论】:

    标签: node.js firebase http-post firebase-cloud-messaging firebase-notifications


    【解决方案1】:

    原来我很笨。我打印出了所有回复:

    console.log(response);
    

    并在最后发现它不起作用的原因:

     body: '{"error":"notification_key already exists"}' }
    

    所以我刚刚尝试了另一个notification_key_name,它就像一个魅力

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      • 1970-01-01
      相关资源
      最近更新 更多