I have used gcm demo code for viewing working of different features of gcm.But unfortunately it is showing some error.My client side is gcm quickstart code ,which is working finely,successfully sent notification using command code(gcm sender) .But i have few doubts-
Is it possible to send message/notification from gcm demo code to gcm quickstart?
2.I have used sender id and api key of gcm quickstart for sending notification from gcm demo.
3.Is there any correction required in gcm demo?
As GCM Reference 401 is authentication issue and possible problems are explained below;
The sender account used to send a message couldn't be authenticated.
Possible causes are:
Authorization header missing or with invalid syntax in HTTP request.
Invalid project number sent as key.
Key valid but with GCM service disabled.
Request originated from a server not whitelisted in the Server Key IPs.
Check that the token you're sending inside the Authentication header
is the correct API key associated with your project. See Checking the
validity of an API Key for details.
Related
It's been a while since I created a Android app with GCM integrated. Previously in the API console you would specify the server IP as a white list. However on my latest project this option is not there. Instead it asks for the SHA1 from the signing key which I have configured.
However when I try to send a notification to a registered device ID I get
"There was an error authenticating the sender account"
I am using the correct API key so I can't see what is wrong.
Previously in the API console you would specify the server IP as a white list. However on my latest project this option is not there
This section is found when you generate a SERVER API key in your GDC.
"There was an error authenticating the sender account"
Found this on GCM Authentication guide. Make sure these are implemented.
A message request is made of 2 parts: HTTP header and HTTP body.
The HTTP header must contain the following headers:
Authorization: key=YOUR_API_KEY Content-Type: application/json for
JSON; application/x-www-form-urlencoded;charset=UTF-8 for plain text.
If Content-Type is omitted, the format is assumed to be plain text.
For example:
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data" : {
...
},
}
Additional Note:
Authentication Error 401 - The sender account used to send a message couldn't be authenticated.
Possible causes are:
-Authorization header missing or with invalid syntax in HTTP request.
-Invalid project number sent as key.
-Key valid but with GCM service disabled.
-Request originated from a server not whitelisted in the Server Key IPs. Check that the token you're sending inside the Authentication
header is the correct API key associated with your project. See
Checking the validity of an API
Key
for details.
Google Cloud Messaging defaults to Firebase Cloud Messaging (FCM) now. Use the Server Key provided in the Firebase Console.
Before that, you may also need to Import your Google Cloud Project into Firebase if you have one.
Import instructions (only follow the "Migrate your console project" section)
I'm getting the error:
Android: Error: Invalid Registration
What could be the possible reason for this? I've followed all the steps given by CleverTap for integration but not sure why the error is still there...
Using GCM.
Based on the error code response, if you receive the error InvalidRegistration try to check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with GCM. Do not truncate or add additional characters.
For more information, you can also check this SO question.
The error "Invalid Registration" typically pops up if either the GCM Sender ID that has been used in the project is incorrect, or if the Server API key you have added to your CleverTap dashboard (i.e., in your Android Push Notification settings) is incorrect.
To solve this, please re-confirm if the GCM Sender ID in your application matches its Project Number from your GCM Console, then please generate a new Server API key, whitelist the required IP addresses (mentioned on the Android Push Notification settings page on the CleverTap dashboard), then go to your Android Push Notification settings on the CleverTap dashboard to re-add the key.
I want to integrate GCM in android application for which I have registered my application and enabled GCM service on google developer console also created the API key.
Where to put this API key in android code ?
Any help appreciated.
You don't have to use api key in android code.
You have to use this api key at server side to send notifications and use project number in android code to register device for GCM and obtain unique device id for receiving notifications.
STEPS TO USE GCM
Register the Android app with GCM to receive Registration Id “RegId“
Share “RegId” with the server
Send a message from server to GCM using HTTP POST request
You can read step by step implementation of GCM here.
I am working on push notifications with Google Cloud Messaging(GCM). I am able to setup server and client side following this tutorial.
The server runs on Apache Tomcat6.0 (localhost) and Android emulator on Google APIs (API level 17). I have a sender id and API key. When run from the emulator, I get a successful device connection message. Sooner after that, upon sending message from server shows the following error.
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 wrong API key is the culprit. But in my case, I made sure I am using the right one from the API console.
By the way, when I run the emulator, I saw a message 'sending regId to server'. What is the registration id? It is not same as sender id; looks like an encoded one.
Any break through?
EDIT
The issue is finally solved! Ant was not properly building the WAR file. So API key hardly gets updated. It was hell of a nightmare to spot the bug. Thanks all for the inputs!
I suggest you to read the GCM guide:
GCM guide for Android
The sender ID is a constant that is going to be used in the comunication between GCM and your server. The regsitratiomID (regID) is managed by the GCM service when your phone registers to his service.
A better definition:
http://developer.android.com/google/gcm/gcm.html
Sender ID:
A project number you acquire from the API console, as described in Getting Started. The sender ID is used in the registration process to identify an Android application that is permitted to send messages to the device.
Registration ID:
An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device.
The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:
Authorization header missing or with invalid syntax.
Invalid project number sent as key.
Key valid but with GCM service disabled.
Request originated from a server not whitelisted in the Server Key
IPs.
Check that the token you're sending inside the Authorization header is the correct API key associated with your project. You can check the validity of your API key by running the following command:
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\"]}"
If you want to confirm the validity of a registration ID, you can do so by replacing "ABC" with the registration ID.
Happens when the HTTP status code is 401.
The Sender ID is the project number what you have created under Google console.
Registration ID
When your application registers to the GCM it gets the registration ID. To deliver the message this registration ID will be used by the GCM to identify your device + your application.
Your android app should send this registration ID to your server so that when server want to send you a message it can tag it with the registration ID, and hence the GCM can deliver it to the right device & right app.
Diagnose whether the registration ID is successfully shared with the server (Get/Post), unless you won't receive any message.
In developer website
there is a Sender Auth Token in the credentials but how to get it?
Please tell me the steps as it is not clear to me.
as Written in Documentation like below.
Sender Auth Token :An API key that is saved on the 3rd-party application server that gives the application server authorized access to Google services. The API key is included in the header of POST requests that send messages.
you can get API KEY from you from HERE
you can get more informations here
EDITED
GCM SERVER SIDE IMPLEMENTATION IN DRUPAL