Question

I follow this guide from google, to set up push notification service for android(GCM). But it is actually a bit wrong, because there is no Register app button, I think it was replaced with credentials in slide bar, then I press create new key button, chose Android then find in eclipse SHA1 key (I try with console, in /home/.android/debug.keystore, there was strange thing, it asks for some password I just press enter), and I add ';com.google.android.gcm.demo.app' - my application package in manifest(it is actually working example from http://developer.android.com/google/gcm/client.html) It works nice, when I enter my SENDER ID(project number from from google cloud console).

Now I am going to write backend for this:

  1. I perform request and get 'Unauthorized' status code on my server(I suggest to skip details, it is actually doesn't matter).
  2. Then I try to curl it, as it was written at google troubleshooting guide here: http://developer.android.com/google/gcm/http.html#auth_error. I got the response with html tags, unauthorized 401.

How should I fix this issue?

Note: I suppose I generate key wrong way because of this mismatch in guide.

Was it helpful?

Solution

I find solution I should open credentials in slide bar -> create new key - SERVER(instead of Android) then don't write any IP, it is enough for development purpose. Then this api key will be valid from server.

 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\"]}"

response:

{"multicast_id":6782339717028231855,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

Then just enter valid registration ID, as written here: http://developer.android.com/google/gcm/http.html#auth_error

It would be nice to change android guide here: http://developer.android.com/google/gcm/gs.html becouse it is not up to date.

OTHER TIPS

APIs & auth -> Credentials -> Create New Key -> Server Key -> Create(don't input IP)

Use Api Key in "Key for server applications"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top