PinchProject / Node-GCMService

Node-GCMService
15 stars 10 forks source link

Error: registration_ids must be a string or an array of 1 element #5

Open barryloh opened 10 years ago

barryloh commented 10 years ago

Hello there,

I've tried declaring

var registration_ids = ['regid1', 'regid2'];

and

var registration_ids = 'regid1';

But it doesnt seem to work. I keep coming back to that error

ghost commented 10 years ago

Hi,

Can you give your code that create this issue ?

Thanks.

barryloh commented 10 years ago

var gcm = require('node-gcm-service');

var message = new gcm.Message(); message.setDataWithObject({ key1: 'GCM Push Message' }); message.setDryRun(false); message.setDelayWhileIdle(false);

var sender = new gcm.Sender(); sender.setAPIKey('apikey');

var registration_ids = ['regid1', 'regid2'];

sender.sendMessage(message.toString(), registration_ids, false, function(err, data) { if (!err) { console.log('Message sent successfully'); console.log('Result: ' + err); } else { console.log('MESSAGE NOT SENT. ERRRORRR ***'); console.log('Error: ' + err); } });

ghost commented 10 years ago

Hi,

I found the bug and correct it (2c125c1bd6a1f37f31cde0aaff67068de8b8543c). I just publish a newer version of module v0.2.8.

Close this issue when all is good for you.

silentjohnny commented 10 years ago

This doesn't fix the problem. Now an array <= 1000 elements will generate up 1000 requests that all fail because of the registration_ids being a string now.

I guess it should be like this:

if (registration_ids.length <= 1000)
    return callback([registration_ids]);
silentjohnny commented 10 years ago

Or maybe better:

if (registration_ids.length <= 1000) array.push(registration_ids);

flocsy commented 9 years ago

Unfortunatelly this is still not fixed