【问题标题】:Chrome web app using firebase returns mismatchsenderid error使用 firebase 的 Chrome 网络应用程序返回 mismatchsenderid 错误
【发布时间】:2016-10-14 04:29:57
【问题描述】:

我很抱歉,因为这个问题已经被问了很多次,但没有一个回答有助于解决我的问题。

我在我的网络应用程序中使用 firebase 并尝试通过 php 或终端 curl 命令发送通知。都尝试过同样的错误:

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

我从同一个地方的 firebase 直接获取 API 密钥和发件人 ID。复制粘贴,没有错别字。检查了大约 50 次... 100% 确定发件人 ID 与 API 密钥匹配,因为我正在从同一屏幕复制和粘贴。

我正在从 Chrome 控制台获取端点:

再次复制和粘贴,没有错别字。

我的 PHP 文件:

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', '**API_KEY**' );
$registrationIds = array('**SUBSCRIPTION_ID**');
// prep the bundle
$msg = array
(
    'message'   => $_GET["message"],
    'title'     => $_GET["title"],
    'subtitle'  => $_GET["subtitle"],
    'tickerText'    => $_GET["ticker"],
    'vibrate'   => 1,
    'sound'     => 1,
    'largeIcon' => 'http://a4.mzstatic.com/au/r30/Purple4/v4/d2/8b/e4/d28be43c-9a6a-4b91-1981-a108ba5cec84/icon175x175.png',
    'smallIcon' => 'http://www.uidownload.com/files/303/56/11/small-arrow-left-fast-rewind-icon.png',
    'click_action' => 'https://aiatsis.gov.au'
);
$fields = array
(
    'registration_ids'  => $registrationIds,
    'data'          => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;

?>

我的清单文件:

{
  "name": "Webpush",
  "gcm_sender_id": "**SENDER_ID**"
}

我使用的 curl 终端命令是:

curl --header "Authorization: key=**API_KEY**" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"registration_ids\":[\"**SUBSCRIPTION_ID**\"]}"

我不知道为什么这不起作用。我试过了:

  • 检查 Key 匹配发件人 ID 大约 150 次。
  • 删除我的 firebase 项目并使用新的 API 密钥和发件人 ID 重新开始(是的,我在执行此操作后生成了一个新的端点订阅 ID)。
  • 如前所述,尝试了 php 和终端推送请求。

我已经用完了所有选项。正如多次提到的,API 密钥已经与相应的发件人 ID 匹配。我对此有 100% 的把握。据我对“MismatchSenderId”错误的理解,他们试图告诉我 API 密钥和发件人 ID 不匹配。他们确实匹配。

  • 发件人 ID 与 API 密钥匹配
  • 订阅 ID 是使用正确的发件人 ID 生成的

有人知道为什么会这样吗?

【问题讨论】:

    标签: web-services curl firebase push-notification firebase-cloud-messaging


    【解决方案1】:

    在清单文件中,que gmc_sender_id 对每个人都是一样的。 将其更改为:"gcm_sender_id": "103953800507"

    【讨论】:

      猜你喜欢
      • 2021-05-19
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      • 2016-04-29
      相关资源
      最近更新 更多