Why is my own sender ID getting back an InvalidRegistration message?

只谈情不闲聊 提交于 2019-12-12 02:24:07

问题


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);

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);

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?


回答1:


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);

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.



来源:https://stackoverflow.com/questions/30740527/why-is-my-own-sender-id-getting-back-an-invalidregistration-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!