来自GCM的MismatchSenderId错误(使用GCM推送通知) [英] MismatchSenderId error from GCM (using GCM push notification)

查看:104
本文介绍了来自GCM的MismatchSenderId错误(使用GCM推送通知)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试发送消息(使用GCM推送通知从服务器发送到移动设备)时,出现以下错误.我已经尝试了stackoverflow其他帖子中给出的所有解决方案

when I try to send message (from server to mobile using GCM push notification) I am getting following error. I have tried the all the solutions that have given in other posts in stackoverflow

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

  1. 我已经在GCM中注册

  1. I have done my registration in GCM

服务器密钥1:xxxxxxxxxx 项目编号:xxxxxx

Server key 1: xxxxxxxxxx Project ID: xxxxxx

在我的android代码中,我设置了以下代码(我的程序包名称为com.revu.revu)

In my android code I have set following (my package name is com.revu.revu)

a.清单文件:

        // When notification received from GCM, then activate this service
        <service
            android:name=".PushNotificationService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>

        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.revu.revu" />
            </intent-filter>
        </receiver>

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.revu.revu.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="com.revu.revu.permission.C2D_MESSAGE" />

b.我已经从GCM服务器获取了注册ID,并将其存储在服务器中.

b. I have got the registration ID from GCM server and I stored in my server.

c.当我尝试使用API​​密钥(服务器密钥)将消息发送到注册ID时,出现上述错误(mismatchsenderId).

c. When I try to send message to registration id with the API key (server key), I am getting above error (mismatchsenderId).

我已经使用以下php代码发送消息

I have used following php code to send message

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxx');
$regId = "APA91bFidqJmnqm0GGmWRmkwB8Kn4fLJ0WPUTbWo3l2bbgQGNnzqbiYKyB4QJ-_JlvoA2tHFhgON2egA_1eJ82TA2sm38qdJVeP2Qk4CW1poxMcFu0emUC1Y_Lf3otKy6U5YAnn2ralS"; 
$registrationIds = array($regId);
// prep the bundle
$msg = array
(
	'message' 	=> 'here is a message. message',
	'title'		=> 'This is a title. title',
	'subtitle'	=> 'This is a subtitle. subtitle',
	'tickerText'	=> 'Ticker text here...Ticker text here...Ticker text here',
	'vibrate'	=> 1,
	'sound'		=> 1,
	'largeIcon'	=> 'large_icon',
	'smallIcon'	=> 'small_icon'
);
$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;

?>

请帮助我,我在这里错过了任何步骤吗?

Please help me, am I missing any step here.

推荐答案

我认为这与您在Google Developer Console中为项目设置API访问权限的方式有关,

I think it has something to do with the way you have set up API access for your project in the Google Developer Console,

不匹配的发件人ID 与一个某些发送者组.当应用程序注册使用GCM时,它必须指定允许哪些发件人发送消息.尝试将消息发送到设备时,请确保使用的是其中一种.如果切换到其他发件人,则注册ID无效.错误代码为" MismatchSenderId "时发生.

Mismatched Sender ID is tied to a certain group of senders. when an application registers for GCM usage, it must specify which senders are allowed to send messages. Make sure you're using one of those when trying to send messages to the device. If you switch to a different sender, the registration IDs don't work. Happens when error code is 'MismatchSenderId'.

以下是讨论MismatchSenderID的相关SO凭单: PHP GCM错误消息MismatchSenderId

Here is a related SO ticket which discuss MismatchSenderID: PHP GCM error message MismatchSenderId

这篇关于来自GCM的MismatchSenderId错误(使用GCM推送通知)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆