i am Roger Li

使用FCM API遇到MismatchSenderId error code

當設定使用Firebase Cloud Messaging 的REST API 發出message時,獲得 "MismatchSenderId" error,本來認為是Android app方面在Register token 時沒有同時提供Server的Sender ID以允許指定Server向裝置發出Push Notification。
跟據官方的Firebase Cloud Messaging HTTP Protocol document有提供MismatchSenderId的建議Troubleshoot方法:

A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work. 

但原來Firebase在Cloud Messaging的設定頁內已發出以下訊息
:

Firebase Cloud Messaging 憑證已經取代傳送訊息所需的伺服器金鑰。雖然您可以繼續使用伺服器金鑰,但我們已停止提供相關的支援服務。

以下是收到的 json:

{"multicast_id":612351507xxxxxxxxxx,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

我嘗試把呼叫API 的Authentication key的伺服器金鑰換成新的Firebase Cloud Messaging 憑證錯誤消失了!

2 thoughts on “使用FCM API遇到MismatchSenderId error code

  1. mr. roger 您好
    我有 一個 PHP - FCM Push 的程式碼測試,我也取得 API_ACCESS_KEY , 可是執行時出現下面錯誤信息:
    {"multicast_id":6048045201822207138,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
    請問是哪裡出問題 ,謝謝!!

    my source code:
    'Testing Notification',
    'body' => 'Testing Notification from localhost',
    'icon' => 'img/icon.png',
    'image' => 'img/d.png'
    ];

    $payload = [
    'registration_ids' => $registrationIds,
    'data' => $msg
    ];

    $curl = curl_init();

    curl_setopt_array($curl, array(
    CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode( $payload ),
    CURLOPT_HTTPHEADER => $header
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
    echo "cURL Error #:" . $err;
    } else {
    echo $response;
    }

    1. Sorry,最近太忙,忘了check留言 ,你的問題解決了嗎? 我估計你只要使用新的"伺服器金鑰"便可.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *