2016-11-29 97 views
5

我试图使用邮递员来测试FCM,但即使FCM令牌存在,我也总是得到以下错误。我在云消息传递标签中获得了令牌:Firebase云消息传递令牌。FCM令牌丢失

<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!", } }: 

回答

14

花了几个小时后,我发现在邮差中,你必须在头文件中加入以下内容。

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" 
    } 

我还发现,你不能消除“到”发送到所有设备:你必须让自己的应用订阅主题。在我的情况下,我让我的应用程序订阅“alldevices”。

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

+0

正要在评论较早添加,但时间流逝了。你做的步骤是一样的,因为我这个[文件]中提供的样品(http://stackoverflow.com/documentation/google-cloud-messaging/5811/getting-started-with-google-cloud-messaging/20474/send -downstream的消息 - 从最云#吨= 201611290600158576573)。做得好。 –

+0

也可以通过在“提供了一个[实例id](http://stackoverflow.com/questions/37671380/what-is-fcm-token-in-firebase/376​​71576#37671576)(令牌)发送到各个设备“字段。 –

+1

是的,答案是正确的。我没有注意到在我的情况下是标记本身之前的“key =”。 – brunoramonalmeida

7

工作的代码,我喜欢这个 -

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." 
    } 
} 
+1

'授权'是标题名称,'key = AAAATI ...'是标题值。 – arberg

+0

对不起。是的,'授权'是标题名称和'key = AAA ....'标题值@arberg – GauravInno