0

I'm learning to use PhoneGap. I want to send a notification to all the users of my app

For that I have register into https://console.developers.google.com and created my app.

I have the API_KEY the PROJECT_NUMBER which looks like: XXXXXXXXXXXX

I have added to my phonegap app the plugin with

cordova plugin add phonegap-plugin-push --variable SENDER_ID="<PROJECT_NUMBER>"

It seems that the plugin is correctly installed. And I dont know how to go through. I know I can make a curl to send a notification, but how should it be?

Could anyone provide a curl example to send to push notification for Android?

EDIT

I'm sending the notification like this:

curl -X POST \
-H "Authorization: key=<API_KEY>" \
-H "Content-Type: application/json" \
-d '{ 
"registration_ids": [ 
  "<PROJECT_NUMBER>"
], 
"data": { 
"message": "Hello Message"
},
"priority": "high"
}' \
https://android.googleapis.com/gcm/send

but I'm receiving a 401 Unauthorized Error. What's wrong?

Community
  • 1
  • 1
Pablo
  • 9,424
  • 17
  • 55
  • 78

1 Answers1

1

registration_ids is an array of device identifiers, not the project number.

If you want to send to all devices without capturing the device id, you could register them to a specific topic. e.g. : topic/foo.

As for how to push a notification via FCM Your HTTP body should be structured like this.

{ "to": "/topics/foo", "data": { "message": "This is a GCM Topic Message!", } }

For more information: Google documentation page : https://developers.google.com/cloud-messaging/topic-messaging

Omri L
  • 739
  • 4
  • 12