Comments (11)
another interesting thing is that I've tried sending from the pushwoosh service, and I'm getting the same issue. It seems like that first androidbegin test link is the only one that gets a push message delivered to the galaxy s2 I'm testing with. Is there some sort of version compatibility where the older Galaxy s2s can't recieve messages from a newer GCM service?
from node-gcm.
I have the same problem. It is possible to achieve a succesful push with PHP code in GCM.php file on this website: http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
Although, using PHP is not what I'm aiming to, so hopefully we could figure that out, together.
from node-gcm.
Okay, I have found the solution for my case. Hopefully, it's useful to you @mypark as well:
var sender = new gcm.Sender(googleApiKey);
var message = new gcm.Message();
message.addData('key1','testdarinodegcm');
message.delay_while_idle = 1;
var registrationIds = [];
registrationIds.push(reg_id);
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
});
http://stackoverflow.com/questions/16410027/cant-receive-data-from-node-gcm
Firstly, it seemed stupid, but funnily it helped. I think devs should take a closer look on differences between making pushes in a usual way and that one provided by khurrum on StackOverFlow.
from node-gcm.
Hello Nonemoticoner! You are perfectly right. Somehow i didn't see this when I first read through the issue. It's a case of simple misunderstanding: the "boilerplate code" is not supposed to be a runnable example, but showing all the different ways the methods can be used. I see how this may cause confusion. Let's fix that right up!
from node-gcm.
How would you have reacted if this was the top of the Usage section?
Usage
To send a message you need to know the Registration IDs of your recipients, and have created an API key for GCM. Here is a simple example of how to send your first notification:
var gcm = require("node-gcm");
// Replace this key with your GCM API key
var sender = new gcm.Sender("YOUR API KEY");
// Replace these Registration IDs with actual Registration IDs
var registrationIds = [
"FIRST_RECIPIENT'S_REGISTRATION_ID",
"SECOND_RECIPIENT'S_REGISTRATION_ID"
];
var message = new gcm.Message({
data: {
testMessage: "This message is transmitted to the recipient device."
}
});
// Actually send off the message
sender.send(message, registrationIds, function(err, result) {
// Handle response from server
if (err) console.error("Something went wrong!", err);
else console.log("Succesfully sent message. Got result", result);
});
The library provides quite a few ways to customize the notifications and the way they are sent. The following is a quick overview:
// Create a message
// ... with default values
var message = new gcm.Message();
... (section continues)
from node-gcm.
@hypesystem I believe the Usage is good enough. I've just talked to my friend with whom I'm working on GCM and it's been just Android application fault. I didn't have any flaws in my Node server-side scripting. I've just ran the previous piece of code I made and it worked for the newer Android app version.
@mypark It's most probably the device fault that push notification doesn't show.
from node-gcm.
Ah. Well that's a relief. Anyway, I think it is clear from @mypark's example that the usage section can lead to confusion.
He has the following lines:
// create a message with default values
var message = new gcm.Message();
// or with object values
var message = new gcm.Message({
// ... (removed for bevity)
});
Here, he instantiates who messages as var message
. This is syntactically broken in Javascript. And we do this in our Usage section. That, I think, is cause for reflection and potentially a revision.
I am going to keep thinking about how to best do this, but your input is valued :) Best of luck with your project.
from node-gcm.
Fixed by #110
from node-gcm.
I used the same code as provided by @Nonemoticoner above:
var sender = new gcm.Sender(googleApiKey);
var message = new gcm.Message();
message.addData('key1','testdarinodegcm');
message.delay_while_idle = 1;
var registrationIds = [];
registrationIds.push(reg_id);
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
});
However, my app client app (react native Android) is still crashing when the notification is sent from the server.
From the server, I get the following success message:
{ multicast_id: 5346493375647405000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [ { message_id: '0:1544767360018299%a0be8ac5f9fd7ecd' } ] }
What could be the possible issue now?
from node-gcm.
@Shivendra30 you would have to look at your client side (Android app) code to figure out what goes wrong on that end. FCM is telling you that delivery was a success, so the error must be in the app.
For this kind of problem, try StackOverflow or AskQuestions.Tech for help debugging. It's unfortunately outside of the scope of this library.
from node-gcm.
In my case, I rebooted the test device and now the notification works.
from node-gcm.
Related Issues (20)
- Address deprecation of request package HOT 2
- How to add analytics label to message? HOT 5
- Unable to send push to browser(firefox, chrome) always getting InvalidRegistration HOT 4
- Make send URI configurable HOT 1
- fcm_options and analytics_label fields are not sent to FCM servers? HOT 2
- TypeError: Cannot read property 'error' of undefined failed_tokens example HOT 1
- Not receiving notifications - ios HOT 2
- Add snyk to fix vulnerabilities faster HOT 15
- Add missing GitHub releases and version tags
- Add CI to require passing tests before release HOT 2
- didReceiveRemoteNotification:fetchCompletionHandler not called. HOT 6
- readme error in failedTokens snippets HOT 1
- Removing no longer valid FCM tokens HOT 1
- Add release automation HOT 2
- Support for Google Service Accounts authorization HOT 2
- Firebase Legacy HTTP API discontinued by June 20, 2024 HOT 12
- request package security issue. HOT 3
- Handle non-HTTP errors HOT 1
- Handle all HTTP errors
- Migration from legacy FCM to HTTP v1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-gcm.