Firebase通知无法通过HTTP.post创建设备组

问题描述 投票:1回答:1

我正在尝试从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个回答
1
投票

事实证明我是愚蠢的。我打印出所有回复:

console.log(response);

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.