2016-11-29 95 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