Closed rumkin closed 8 years ago
Hey @rumkin, Can you please post the code you are using to send the notification?
My first guess would be that you passed an invalid API key in the following line:
// Set up the sender with you API key
var sender = new gcm.Sender('YOUR_API_KEY_HERE');
My API key was working during this morning before nodejs version update from 5.4 to 5.10.
I'm sending pushes with this code:
this.gcm = new gcm.Sender('YOUR_API_KEY_HERE'); // ...with proper API key
// ....
var message = new gcm.Message();
message.addData({
text: text,
sound: sound,
badge: badge,
params: JSON.stringify(data)
});
this.gcm.send(message, {registrationIds: [token]}, function (error) {
if (error) {
console.error(error);
}
});
@hypesystem any ideas?
No idea, no...
From a similar issue:
Solved: OS language wasn't english, so chars in header were not identified -> TypeError('The header content contains invalid characters')
Could this be the problem?
According to this issue from request, which we use underlying, it can happen when URLs contain invalid characters. The fix is calling encodeURI(decodeURI(url))
.
The error is thrown, and not propagated properly. It seems that this can be fixed by updating the request version we use.
Interesting theory!
Would love to verify it -- @rumkin, can you add the following code to node_modules/node-gcm/lib/sender.js
and then try sending a push notification? It will echo the request headers to the Node.js console.
Find in sender.js
:
var post_req = req(request_options, function (err, res, resBodyJSON) {
Add below:
console.log(res.req._header);
Then, try to send a push notification and paste the headers here, please.
Nope.
/app/source/node_modules/node-gcm/lib/sender.js:109
console.log('gcm_headers', res.req._header);
^
TypeError: Cannot read property 'req' of undefined
But there is a error object which content is equal to the first comment's error.
Looks like you're using an outdated version of node-gcm.
Which version are you using now? Try to update node-gcm to 0.14.0
.
Solved. Problem was in '\n' char in the key. Probably key should be validated?
Thanks for help.
I've got http error on sending gcm pushes: