chiranjib
chiranjib

Reputation: 5308

Google Cloud Messaging (GCM) issue

I am using the Google Cloud Messaging (GCM) sample code for both client & server. I have successfully setup the server using Apache Tomcat & also created the Android application (apk) following the steps provided on the tutorial.

After deploying the war file on the Apache Tomcat, I am able to register from emulator. I have provided a Public IP for the Tomcat server & able to view the "registered screen" from the mobile Browser using GPRS.

I have followed all the steps provided on the GCM tutorial.

Is there any issue with the sample code of the GCM?

I am getting the following exception when I am clicking on a button to send Message to the registered device:

com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401 com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177) com.google.android.gcm.server.Sender.send(Sender.java:121) com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:82) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I have gone through some similar posts but am not finding any exact solution on the issue. Any suggestions / hints will be helpful.

Upvotes: 2

Views: 3191

Answers (3)

Orr
Orr

Reputation: 4840

Google has updated their api console recently to Google Cloud Console. In short terms , you need to create an Android application and pick Accessing APIs via a web server. this service has a detailed guide for that

Upvotes: 4

ricardo
ricardo

Reputation: 41

I had the same problem using tomcat as server, to fixe it I modified this file

WebContent/WEB-INF/classes/api.key replacing the content with the API Key extracted from the google api console.

I hope it helps.

Upvotes: 4

Sparky
Sparky

Reputation: 8477

That's the Not Authorized return code. Your server app is not authenticated to the GCM server. Did you generate yourself an API key in the developer console?

Upvotes: 0

Related Questions