GCM giving blank response After regenerating API KEY - php

I am using Google Cloud Messaging from last one year with PHP as server side script and it is working fine on all app until I hasn't sent notification to one of the may application for one month then after that while sending notification to same app I gets blank response like
{"status":[],"0":"\n\n
so I assumed that google may have deactivated my API key so I regenerated my API key from developer console and replaced regenerated key with old key on server side and at that time it had worked I was able to send message again but after two week again I am getting blank response like given above and this time I was sent notification to same app everyday.

From this related SO question. It suggested to make sure that it's retrieving the POST variable in your PHP code.
Try to replace this:
$message = array("Notice" => $_POST['message']);
with:
$message = array("Notice" => "testing");
You can also check on this tutorial and thread on how to integrate GCM in PHP backend properly.

Problem is solved after importing project into firebase.
Server API Key is auto generated by google services and after using those keys on server site i am able to send notification.

Related

sending fcm notification messages to multiple android devices by registration_ids parameter

I want to send notifications to multiple android devices(where same app is installed) by fcm from php server side by calling this url -
https://fcm.googleapis.com/fcm/send
I checked sending messages to device groups but my requirement is such that there will not be definite devices to which i will send messages because i am going to do it in a hourly cron job, and each time a cron job runs it will send notification messages to different different devices according to requirements. or can it be done in another way?
But i am thinking to use "registration_ids" parameter instead of "to" parameter, details of these fields here in the Downstream HTTP messages section. In this registration_ids field i will put all required device registration tokens in array. Now my question is after receiving message in android device can the message be parsed in the android app sdk codes?. i am in a bit of doubt as in this documentation there are no mentions of registration_ids parameter when sending messages to multiple android devices. Please assure me. And furthermore, will the message be sent when android app is in background?!. Please don't write one line, provide some examples if possible.
In the documentation for building requests to send to multiple devices you will find an example of passing multiple FCM tokens in a single call to the FCM API in the tokens parameter (in Node.js) or by using a HTTP batch request with multiple subrequests (in the REST API).
If you're having a hard time making this work, posting a question that shows what you tried increases the chances that someone can help making it work.
Yes, the message is sent regardless of whether the app is in the foreground, or in background. Whether the notification is actually shown depends on many more factors, many of which are outside of your control (such as the Android version, device maker/OEM, and the user settings).

How to retrieve Registration ID on Android Device in WinDev Mobile 20?

I'm new to WinDev Mobile. In the project that I'm working on, there is a need for implementing Push Notification with use of GCM.
The notification will be sent from PHP script running on our web server.
For this, it is necessary that the mobile app registers with Google Cloud Messaging (GCM) . This seems to work, But I'm getting the Registration ID like this as a String type.
!‘‰åpWx£Üx½ZÌì–´äUü;jÚÿ†Pȧ#úùrjIìÑtð*æW‹1ç‰Yæµß;Ar‘ýãU»ç
I've to do this because I'm not able to send Buffer content to MySQL. For communicating between mobile app and MySQL I'm using c_PHP4WM 7.0 webservice.
In MySQL the field name is pn_reg_no and its datatype is text. Is this correct?
Try to convert that string with function StringToUTF8()

Sending push messages to all open chrome browsers via GCM

I am trying to develop a web site which will send push notifications to all users currently watching it. I found some tutorials on how to send pushes to myself using GCM for Chrome and they are working fine,
(https://github.com/gauntface/simple-push-demo)
but I cannot understand how to send pushes to every user who is currently on my site and allowed to receive them. As far as I understand I need to collect their browser IDs when they subscribe
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe({ userVisibleOnly: true })
.then(onPushSubscription)
but I cannot find how to get and store them (perhaps in MySQL DB with PHP code) and after that how to send a push to everyone (probably to iterate over all browsers IDs in my DB and send pushes to everyone separately with cURL requests). On my site I have code which uses ServiceWorkers and handles users subscription but everything is working for me only. Noone who is else on a site does not receive any notifications. Any help would be appreciated.

InvalidRegistration both on C2DM & GCM

I'm trying to send Push Notifications via C2DM / GCM to an Android Application via PHP.
No matter which i use, i keep getting the following :
For GCM :
{"multicast_id":7672049265453358197,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
For C2DM : Error=InvalidRegistration
After reading allot about this issue all day I'm still clueless as to why this is an InvalidRegistration as if i take the registatoin_id and use it to send a test push message via Urban Airship it works.
Notice that this is not an auth issue as i get a [http_code] => 200 back from google and not 401.
If i send an empty registatoin_id or even omit just one char from it the error message changes to "MissingRegistration".
Any help would be appreciated.
If you copied the apid from UrbanAirship then that's the problem:
http://docs.urbanairship.com/reference/glossary.html#term-apid
Airship Push Identifier
APID
APIDs identify devices with transient registration IDs, such as Windows devices.
These identifiers are version 4 UUIDs, and are 36 characters long, including dashes.
You need to get the device information from http://docs.urbanairship.com/api/ua.html#get--api-apids-(APID) in the "gcm_registration_id" property. That's the registration id needed.
It seems you need to then keep track of that registration id as it is transient as suggested by UrbanAirship. But that's another topic.

EasyAPNS delivered the message but not received on iOS device

I'm using EasyAPNS as PHP server script to send Push Notifications to iOS devices.
It worked perfectly in development using Apple Development Push Notifications Certificate, but when switched to Distribution it set the message as "delivered" but never received on iOS devices downloaded from App Store!
I have tested Apple Distribution Push Notifications Certificate along with my app downloaded from the App Store using this Script and it worked perfectly! So the problem is not from my distribution certificate nor from my app, it's somewhere in EasyAPNS scripts and settings but I have no idea where is it and how to fix it!
Check if your using the right servers.
In your testing using that script, was development set to false? Or true depending on which example your using. Check if either of these result in the correct use of the production server.
$development = true; // boolean
I found the bloody reason :)
The payload in apns_messages.message column was not inserted as a complete payload format due to a long message used, so the content of the message field was like the below:
{"aps":{"alert":"\u064a\u0627 \u0639\u0644\u064a \u0623\u0646\u062a \u0627\u0644\u0648\u0644\u064a \u064a\u0627 \u0639\u0644\u064a \u0623\u0646\u062a \u0627\u0644\u0648\u0644\u064a \u064a\u0627 \u0639\u0644\u064a \u0623\u0646\u062a \u0627\u0644\u0648\u064
So the change I made was to make sure use a very short message to make sure EasyAPNS insert a complete payload message format in apns_messages.message column, so the content of the field is like the below:
{"aps":{"alert":"\u064a\u0648\u062c\u062f \u0625\u0639\u0644\u0627\u0646 \u062c\u062f\u064a\u062f \u0645\u0646 \u062e\u062f\u0645\u0629 \u0628\u0644\u063a\u0646\u064a","badge":5,"sound":"alarm.caf"},"module":"messages","id":"28"}

Categories