InvalidRequestException: HTTP Status Code: 401

912 views
Skip to first unread message

KALIRAJ Sa

unread,
Jun 16, 2016, 7:24:46 AM6/16/16
to android-gcm
Hi,

I am experiencing the exception while try to send the message to GCM.

com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
    at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
    at com.google.android.gcm.server.Sender.send(Sender.java:121)

below is my snippet:

Sender sender = new Sender(GOOGLE_SERVER_KEY);
        Message message = new Message.Builder().timeToLive(30).collapseKey("1")
                .delayWhileIdle(true).addData(MESSAGE_KEY, notificationiMessage).build();
        Result result = sender.send(message, registrationId, 2); // I am getting exception here...


appreciating your help :)


 

Diego Giorgini

unread,
Jun 17, 2016, 2:57:49 AM6/17/16
to android-gcm
Hi Kaliraj,

please check that you are using a server type api-key, and not a client api-key.
If you are using Firebase you can find the API-KEY in Project Settings > Cloud Messaging
If you are using cloud console, or you are not sure which key you are using, 
you can generate a new key through through https://console.cloud.google.com 

More documentation see: "Server key" here:
 

--
You received this message because you are subscribed to the Google Groups "android-gcm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-gcm...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-gcm/1b9b2b3b-2c15-44ba-ad9e-178b69af8438%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages