FCM令牌丢失

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FCM令牌丢失相关的知识,希望对你有一定的参考价值。

我正在尝试使用Postman测试FCM,但即使FCM令牌存在,我总是会收到以下错误。我在Cloud Messaging选项卡中获得了令牌:Firebase Cloud Messaging令牌。

<html>
<HEAD>
    <TITLE>The request was missing an Authentification Key (FCM Token). Please, refer to section &quot;Authentification&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>
</HEAD>

这是我发送的内容。

POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Cache-Control: no-cache
Postman-Token: 9109eb13-245f-0786-21a5-6207f5426b44

Content-Type:application/json
Authorization:key=AAAAfnYrKvU:APA91bFwgeM3zuFId6UDzvIHk9qZ3lKHnX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
{  "data": {     "message": "This is a Firebase Cloud Messaging Topic Message!",    } }:
答案

花了几个小时后,我发现在邮递员中你必须将以下内容放入标题中。

Key: Content-Type
Value: application/json
Key: Authorization
Value: key=AAAAfnYrKvU:APA91bFwgeM3zuFId6UDzvIHk9qZ3lKHnX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(Firebase Cloud Messaging token)

然后单击Body并选择Raw,在这里添加json。

    {
        "data": {
            "title": "new messages",
            "score": "5x1",
            "time": "15:10"
        },
        "to": "/topics/alldevices"
    }

我还发现你不能通过消除“to”来发送到所有设备:你必须让你的应用订阅一个主题。在我的情况下,我让我的应用订阅了“alldevices”。

现在我可以发送“to”:“/ topics / alldevices”,所有应用都会收到通知。

另一答案

像我这样的工作代码 -

POST: - https://fcm.googleapis.com/fcm/send

报头 -

 Content-Type: application/json
 Authorization:key=AAAATIOk_eI:APA91bHR-NRuK-cVTc0fsdQ-N4SOAzocN7ngomFzcV7GkeCCHb6PmCFl_7MXTEPbdw-r0MTU9UmSbyxaSxxxxxxxxx.....

身体-

 {
"registration_ids": ["fBclzMXz1UQ:APA91bE268ddn8DNB95LcU2XyhjjOXE-8PJ1nZ8y0yf1-4UuUX0fFNuae9Acj5BLYZwJq72tnNUjcUax9ZvRxxxxxxxxxxxxxxxxx...."],
"notification": {
    "title": "Hello",
    "body": "This is test message."
    }
}
另一答案

工作代码......

make sure You subscribe to topic ="/topics/alldevices" in your android/ios code.

POST: - https://fcm.googleapis.com/fcm/send

报头 -

Content-Type: application/json
Authorization:key=AAAAPfs2N44:APA91bFcDkUfTjbFQvrttpedPcZINcjNkofU_x35xxxxxxxxx.....

身体-

"notification":{
"title":"TITLE",
"body":"BODY",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
"data":{
"landing_page":"second",
"price":"$3,000.00"
},
"to":"/topics/alldevices",
"priority":"high",
"restricted_package_name":""
}
另一答案

这是一个使用令牌向设备发送通知的邮递员POST请求示例。

Type: POST
Url: https://fcm.googleapis.com/fcm/send

Headers
key: Content-Type,
value: application/json

key: Authorization,
value: key="This is the key in your FCM project console->Settings->Cloud Messaging->Server Key""

    body: "mode": "raw"

    { 
     "to": "Token/s received to mobile end",  
     "notification" : {
     "body" : "message",
     "content_available" : true,
     "priority" : "high",
     "title" : "title of the notification"
     }
    }

以上是关于FCM令牌丢失的主要内容,如果未能解决你的问题,请参考以下文章

FCM 到多个设备(令牌)列表

Flutter:如何在 Flutter 中为 Firebase (FCM) 注册令牌订阅ToTopic

使用 php 向 ios 设备发送带有 fcm 令牌的远程通知

提供的注册令牌无效。确保它与客户端应用从 FCM 注册时收到的注册令牌匹配

当android应用程序注销并与另一个用户登录时如何重新生成新的FCM令牌

使用 FCM Android 推送通知并删除令牌