该请求缺少身份验证密钥(FCM令牌)。请参考“身份验证”部分。 FCM文档

时间:2019-09-29 16:47:05

标签: angular nativescript

我正在使用angular httppost模块从我的nativescript应用发送Firebase通知,有时发送通知,有时返回错误,该请求缺少身份验证密钥(FCM令牌)。请参阅FCM文档的“身份验证”部分

如果应用程序在前台,则使用邮递员,它不会收到通知,但响应仍然成功,但是如果应用程序在后台,或者我在android上按主页按钮,它将收到通知 这是邮递员的一瞥

sendtoken(id, detail) {
        console.log("????????????????????????????????????????????????");
        console.log(JSON.stringify(detail.firebase_token));
        console.log(JSON.stringify(this.DataService.activeJob));
        console.log("\n\n" + detail.JobID);
        var job = this.DataService.activeJob.filter(f => detail.JobID === f.jobID)[0];

        // + detail.amount + "\n Origin : " + job.jobOrigin + "\nDestination : " + job.jobDestination

        var data = {

            notification: {
                "title": "JOB",
                "text": "Your Firm was allocated a job of amount :",
                "sound": "default"
            },
            "priority": "High",
            "to": detail.firebase_token
        };

        // alert(JSON.stringify(data));
        var ServerSettings =
            {

                serverpath: "https://fcm.googleapis.com/fcm/send"
            };

        this.headers.append("Authorization", "key=AAAA9wyBPKg:APA91bGI6dOOM42iTJNqO47xMC9QIkLHf738Sn1iVk0gbkZDND1fuP9zBW1A38DlhupDdvlsAZCJu1iNACjbVvtdZQd3ePXnq1xctwYQ3PCErchmyYMM4UvmWjeeNjn2X1IL9mgy5ioT");
        this.headers.append("Content-Type", "application/json");
        this.options.headers = this.headers;
        //this.setHeaders();
        console.log("\n\nSending to Server for Update :\n\n" + data);
        let url = ServerSettings.serverpath;

        return this.httpmodule.post(url,data, this.options);

    }

与邮递员

 {
        "notification": {
                "title": "JOB",
                "text": "Your Firm was allocated 5",
                "sound": "default"
            },
            "priority": "High",
            "to": "dwu1TEW5sPM:APA91bEppyye2NCq5IAfnjJg95eTsnsPf4Vn3U8CLgvUjJnY7uAVs4ASZiu1RCuFKf7uzXYojAGzKQD8cflKRGvpiqhEymbhK-DB-LQi8MogWIyyIR_xOm64GIpbviWrDuVZt8Td6xZ2"

        }

与邮递员回复

{
    "multicast_id": 6341518491186981658,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "0:1569773536386430%0a6c29b00a6c29b0"
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

  

如果您始终希望在应用程序处于运行状态时显示通知   在前台发送时不发送其他参数/​​数据   推送通知,您需要设置   将showNotificationsWhenInForeground选项设置为true:

IF(C3=" ", B3, C3)

Reference from plugin docs

编辑:

使用Angular更新标头时,您应该将现有实例替换为firebase.init({ showNotificationsWhenInForeground: true, }); 方法返回的新实例。

append