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

618 views Asked by At

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

There are 1 answers

2
ianhanniballake On BEST ANSWER

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.