gcmsender错误:MismatchSenderId

时间:2016-02-19 21:53:50

标签: android push-notification google-cloud-messaging

我正在使用他们的示例应用测试更新的Google gsm云服务 https://github.com/googlesamples/google-services/tree/master/android/gcm 我在这里关注谷歌教程: https://developers.google.com/cloud-messaging/android/start

设置了设备客户端,我收到了令牌,我已经在我的开发者控制台上下载并配置了google-services.json。

我知道gcmsender模块使用API​​密钥发送测试消息,但是我收到错误:     "结果":[{"错误":" MismatchSenderId"}]} 我已确认google-services.json使用的是与开发者控制台提供给我的发件人ID相同的发件人ID。 我错过了什么?

3 个答案:

答案 0 :(得分:4)

请在终端下面的脚本中运行

curl -X POST \
-H"授权:key =在这里写api_key" \
-H" Content-Type:application / json" \
-d' {
" registration_ids":["写在这里reg_id由gcm&#34生成;],"数据":{"消息":"手动推送来自Rajkumar的通知" }, "优先":"高"
}' \ https://android.googleapis.com/gcm/send

MismatchSenderId,因为在同一设备中,您使用不同的密钥记录。解决此问题卸载应用程序并运行它againg并更新注册密钥。然后在你的teminal中运行CURL脚本,我在上面发布它将给出成功消息,你将收到通知你的设备

答案 1 :(得分:0)

基于Official Google Documentation。您将收到' 错误:MismatchSenderId '当注册令牌绑定到某组发件人时。当客户端应用程序注册GCM时,它必须指定允许哪些发件人发送消息。您应该在sending messages到客户端应用时使用其中一个发件人ID。如果您切换到其他发件人,现有的注册令牌将无法正常工作。 检查发件人ID API_KEY ,在Google Developer Console中生成API密钥并用于通过GCM进行身份验证/授权,Android应用使用发件人ID注册物理设备与GCM,能够收到notfications。确保API密钥属于服务器应用程序的密钥'

答案 2 :(得分:0)

如果您使用cordova插件phonegap-plugin-push,那么很可能您在npm package.json中定义了您的发件人ID,如下所示:

{
  "id": "phonegap-plugin-push",
  "locator": "phonegap-plugin-push",
  "variables": {
    // TODO: this sender ID should probably be moved into a config file that can be inserted by a deploy script
    "SENDER_ID": "2342343443"
  }
},
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard",
"ionic-plugin-deploy"

...

如果您未设置发件人ID或在后端更改Google API控制台项目并忘记更新应用程序的前端部分,则会发生错误。

Google API控制台中的发件人ID已被隐藏。转到此处,向下滚动查看最近的答案:Android GCM SENDER_ID, how to get it?

在这两个位置,发件人ID必须相同。别忘了重新部署/重新安装你的应用程序。

相关问题