使用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.
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;
}
Sorry,最近太忙,忘了check留言 ,你的問題解決了嗎? 我估計你只要使用新的"伺服器金鑰"便可.