ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

Error 401 #227

Closed pcnetsoft-projects closed 8 years ago

pcnetsoft-projects commented 8 years ago

I tried to solve this problem, and i have been read the other issues, but didn't slove

I got 401 error:

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

  var message = new gcm.Message();
  message.addData('key1', 'msg1');
  var regTokens = ['MY_DEVICE_REG_ID'];
  var sender = new gcm.Sender('MY_SERVRE_API_FROM_GOOGLE');
  sender.send(message, {
    registrationTokens: regTokens
  }, function(err, response) {
    if (err) console.error('Error : ' + err);
    else console.log('response' + response);
  });`
eladnava commented 8 years ago

Looks like you didn't replace the GCM API key with your own key.

Check this out: https://github.com/ToothlessGear/node-gcm/issues/151

pcnetsoft-projects commented 8 years ago

It's solved.

I didn't change anything, but it's need more time to be activated in Google.

hypesystem commented 8 years ago

Thanks for letting us know what caused the problem -- good to know if anyone encounters this in the future :smile:

pcnetsoft-projects commented 8 years ago

The problem is back to me, I don't know why, and i need to solve it .

You can check this example(Real API and token key) https://tonicdev.com/5712577524d46e1200acede5/571a677d05a61111000d0e0d

eladnava commented 8 years ago

What kind of API key are you creating in the Google APIs Console?

Server key? Browser key?

pcnetsoft-projects commented 8 years ago

I used the Server Key. I'm building APIs for my own Android application, and using Nodejs/Express for that.

eladnava commented 8 years ago

Please try creating and using a Browser Key without any referrer restrictions to see if the 401 error goes away.

hypesystem commented 8 years ago

As far as I can tell using a server key should be fine. 401 is returned directly from GCM, which states that it is an error with authentication of the sender account. It sounds like you are either passing a wrong key (copied incorrectly, or similar).

eladnava commented 8 years ago

I recall having an issue when GCM was first released, during the first week, that only a browser key would work for some reason. It is definitely a shot in the dark, though.

hypesystem commented 8 years ago

Any news, @pcnetsoft-projects ?

hypesystem commented 8 years ago

Closed due to lack of response.

pcnetsoft-projects commented 8 years ago

Hello Team,

Sorry for the late, it was an emergency issues. Now, It's working with me when I changed the key to 'Browser Key'.

Thanks guys.

pcnetsoft-projects commented 8 years ago

And I hope so that you can give me more details about the Error, not the status number only, we need a message or something like that to explain whats the error.

Good job :)

rmehare1 commented 6 years ago

i can solve it by replace Browser key to server key(now using)

atulmy commented 5 years ago

There are two keys in https://console.firebase.google.com/project/projectId

Got it working with Legacy server key

You can only Legacy server key "Server key (auto created by Google Service)" listed in https://console.cloud.google.com/apis/credentials?project=projectId