问题描述
我一直在努力实现在应用程序GCM和基于谷歌的例子已经能够得到它的工作。然而,当我试图用我自己的发件人ID和范围,我回来了 InvalidRegistration
错误,当我尝试发送一个通知。例如,这个作品:
I have been working on implementing GCM in an application and based on Google's examples have been able to get it to work. However, when I try to use my own sender ID and scope, I get back an InvalidRegistration
error when I try to send a notification. For example, this works:
token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
在哪里,因为这不,我已经双从项目检查发件人ID,其实有我的开发者控制台只有一个项目,现在,所以没有办法,我可能会使用不正确的一项:
Where as this does not, I have already double checked the sender ID from the project, in fact, there is only one project in my developer console right now, so there's no way I could be using an incorrect one:
token = instanceID.getToken(getString(R.string.my_sender_id), SubscriptionHelper.INSTANCE_SCOPE, null);
我缺少的重要组成部分吗?为什么会使用默认的发件人ID工作,但不与发件人ID我从开发者控制台获得的?
Am I missing a key component here? Why does it work with the default sender ID, but not with the Sender ID I've obtained from the developer console?
推荐答案
%的的,您的实例id令牌调用应该看起来像
Per the GCM Android Client guide, your InstanceID token call should look like
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(
getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE,
null);
您注意必须使用 GoogleCloudMessaging.INSTANCE_ID_SCOPE 作为第二个参数 - 实例id不仅仅是GCM比较一般,因此为什么它是一个可以采取任何字符串参数,但GCM特别要求授权范围
Note that you must use GoogleCloudMessaging.INSTANCE_ID_SCOPE as the second parameter - InstanceID is more general than just GCM, hence why it is a parameter that can take any String, but GCM specifically requires that authorization scope.
这篇关于为什么我自己的发件人ID取回的InvalidRegistration消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!