Google GCM server returns Unauthorized Error 401 while subscribing - google-cloud-messaging

I get subscription success in app. But I see Google GCM server returns Unauthorized Error 401 in the server logs.
When I push a message from adapter, I get an authorization failure in server logs. But My adapter gives success response Notification sent to set user.
Can somebody tell me what could be the mistake I would be doing. (can this error also occur when my firewall is restricting this call.)
While subscribing i was getting Reason: 401 unable to authenticate with gcm services. something like this. And While pushing a notification from adapter i was getting reason : unable to authenticate for Api key "ASYI-" with GCM. the error messages may not be exact but the message means just like above
I am getting below error while sending notification
Failed to invoke Google GCM push service.
GCM Service invocation failed (reason: Authentication has failed for sender key starting with 'AIzaSyCk')
also getting below error
GCM push token 'ssdsddsdsdsds' is not added to GCM notification key. GCM Service invocation failed (reason: Returned HTTP/1.1 401 Unauthorized when invoking GCM push service to get the notification key.)
GCM Service invocation failed (reason: Returned HTTP/1.1 401 Unauthorized when invoking GCM push service to get the notification key.)
on the Android studio i see below error :
GCMAPIClient$BackgroundRegistrationHandler.run in GCMAPIClient.java:130 :: Failed to register with GCM using Google Play Services. Error:Error :INVALID_SENDER

Finally it worked for me, two things i did it to work.
Took the GCM.jar file from the sample project and placed it in my project . removed the other gcm dependencies
Created a project in FCM Console (https://console.firebase.google.com/)
and took the google-services.json and placed it in my android studio project under app. Took the web API key from FCM Console and placed it in the mobilefirst app project.(There are two keys now one for app and other for web).
I had to create a new project in the fcm console and new keys..

Related

Mulesoft error message propagation through deployed application

General explanation of the problem:
how can i get/log inside an application B, the error/exception message produced by an application A (error description and code are generated with a OnErrorPropagate). Application A is a Process API and B is an Experience Api both deployed on cloudHub.
More Details:
i have a Process API App. and a Experience API APP. deployed on CloudHub that retrieve client data from a DB.
.../getClient?client_Id=xxx
When inside the request the client_id params is not provided the below error message (generated inside an OnErrorPropagate) is shown
"message" : "bad request"
When a client call the Exp.API APP /getClient without the parameter, the PROCESS API APP (invoked by a flow inside the Exp.API implementation) respond with the above error message.... how can i retrieve this message in my Experience API Application?
If i try lo log the payload response (that should contain the error message) from an Experience API APP log, i always get an empty message.
So, is possible to pass an error message generated inside an OnErrorPropagate from an application (PROCESS API APP) to another app (EXPERIENCE API APP)?
All these applications are on cloudhub. Mulesoft 4
You can capture the the error response payload from the process API which will be present in the error object and set it as response for your experience API using this DW expression
#[output application/json --- error.exception.errorMessage.typedValue]
You should capture the payload response in the Experience API when you make the HTTP request to the Process API.

'Code:Messaging/Incorrect-GCM-sender-id' error message in browser

In my web application i was taking GCM ids. Now to move to FCM, we added the code to get the token generated and also changed the sender id in manifest.
In our case, since we lost the old gmail id associated with our old GCM token, we are using a new account & new FCM key.
Getting the below error:
Unable to get permission to notify. Or {code:
"messaging/incorrect-gcm-sender-id", message: "Messaging: Please change
your web app manifest's '…e messaging.
(messaging/incorrect-gcm-sender-id).", stack: "FirebaseError: Messaging:
Please change your web
a…gstatic.com/firebasejs/5.9.3/firebase.js:1:29212)"} code:
"messaging/incorrect-gcm-sender-id" message: "Messaging: Please change
your web app manifest's 'gcm_sender_id' value to 'XXXXXXXXXXX' to use
Firebase messaging. (messaging/incorrect-gcm-sender-id)." stack:
"FirebaseError: Messaging: Please change your web app manifest
I think you'll need to unregister any current subscriptions and re- subscribe the user.

Api Auto Discovery error in mule logs

Api Auto discovery Error 400... when i deploy my api in cloud(anypoint through runtime manager) it got deployed. but, when i tried to get a response from postman, it says "service not available",i am not able to get a response back from postman.
Is it error 503? In that case the explanation is that the API is not correctly paired to the API in API Manager with client credentials and Autodiscovery. See https://support.mulesoft.com/s/article/API-returns-503-Service-Unavailable-error-to-clients

stop gcm to send notification on old registration id

Suppose that case when the client app has re-registered with the gcm itself but the server is unaware of this and now the server is sending notification to that particular client what I want is the notification should not be sent with the old registration id. How can this be done?
If your server sends a message to an invalid Registration token, it will probably receive a NotRegistered error response. You should handle this error accordingly by removing the corresponding token. As per the documentaion I linked above:
For all these cases, remove this registration token from the app server and stop using it to send messages.

HTTP Status Code: 401 in GCMDemo

Reference:http://developer.android.com/google/gcm/demo.html
Server 401 when trying to send a message to my android device.
HTTP Status 500 - HTTP Status Code: 401
type Exception report
message HTTP Status Code: 401
description The server encountered an internal error (HTTP Status Code: 401) that prevented it from fulfilling this request.
exception
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(SendAllMessagesServ let.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.
Could anybody tell me how to solve?Thank you!
You should take a look at the GCM docs where it explains the GCM response: http://developer.android.com/google/gcm/gcm.html#response and troubleshooting the 401 error code: http://developer.android.com/google/gcm/gcm.html#auth_error
Description from the docs:
Authentication Error
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.
So I would check to make sure that you are setting you authorization header properly and that you Google Project number is properly setup with GCM and accepting your servers IP.