When my backend server sends post requests to GCM servers I get an authorization error HTTP 401.
I followed the steps described here:
http://developer.android.com/google/gcm/http.html#auth_error
>> api_key=AIzaSyDEy3...
>> curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_id\":\"ABC\"}"
I get this:
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
In the troubleshooting it says:
Authentication Error
The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:
1. Authorization header missing or with invalid syntax.
2. Invalid project number sent as key.
3. Key valid but with GCM service disabled.
4. Request originated from a server not whitelisted in the Server Key IPs.
I have questions about that:
- Is the header in the curl request correct?
- Do they mean "api_key" (AIzaSy…) or the Project number like 8305134….?
- How do I whitelist my Server Key IP?
- If I'm running the curl command, do I have to whitelist the IP-Address of my computer?
I don't know the syntax of the
curl
command, but it seems strange that one header you specify as--header "key: value"
while the other is specified as--header key:"value"
. Perhaps one of them is incorrect. In addition, you should changeregistration_id:ABC
to"{\"registration_ids\":[\"ABC\"]}"
.They mean the API Key.
If you didn't define a list of white listed IPs when you created your API Key, it should be white listed by default.