Connecting to a GCM server running on a local server

I am working on push notifications using Google Cloud Messaging (GCM). I can configure the server and client side after this lesson .

The server runs on Apache Tomcat6.0 (localhost) and the Android emulator in the Google API (API level 17). I have a sender id and an API key. When I start from the emulator, I get a message about the successful connection of the device. After that, after sending a message from the server, the following error is displayed.

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

From other posts, I understand that the wrong API key is the culprit. But in my case, I made sure that I was using the correct option from the API console.

By the way, when I run the emulator, I saw the message "sending regId to the server." What is a registration id? This is not the same as the sender ID; looks like encoded.

Any breakthrough?

EDIT

The issue is finally resolved! Ant incorrectly created the WAR file. Therefore, the API key is unlikely to be updated. It was a nightmare to discover a mistake. Thank you all for your contribution!

+5
source share
3 answers

I suggest you read the GCM manual:

GCM Guide for Android

Sender ID is a constant that will be used in communication between GCM and your server. RegsitratiomID (regID) is managed by the GCM service when your phone registers with its service.

: http://developer.android.com/google/gcm/gcm.html

:

, API, . Android, .

:

, GCM, Android, . , Android , , , Android. , Android-, .

+2

, , . :

  • .
  • , .
  • , GCM.
  • , IP-.

, , , API, . API, :

 api_key=YOUR_API_KEY

 curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send  -d "{\"registration_ids\":[\"ABC\"]}"

, , "ABC" . , HTTP 401.

+2

- , Google.

GCM, . , GCM + . Android , , , , , , GCM .

, (Get/Post), .

0

All Articles