FCM - Send to all users/devices from a PHP script [duplicate] - php

I have created a small App that's able to receive Push Notifications from the FCM Console.
What i want to do now is to send a Push-Notifications to all Android Phones that got the app Installed using the API. And this is where i got completely lost.
Is there no way to send it to all Phones without collecting all the registration-ids?
Does this only work with the Console but not with the API?
thanx in advance

Sending a message to all the phones like what you do from the Firebase Web Console is only possible from the Web Console.
If you need this feature from the API you can submit a feature request:
https://firebase.google.com/support/contact/bugs-features/
Another possibility is to have all the client registering to a specific topic via FirebaseMessaging.getInstance().subscribeToTopic(topicName)
In this way you can send a message to the whole topic without collecting the registration-ids manually.

Related

Send FCM message to specific Google user without need to install an app?

I'm doing a tiny personal project involving an Arduino and a PHP backend. I want to send a push notification from the PHP backend to my Android phone using Firebase Cloud Messaging. This question is specifically about FCM - I don't want to use any other services like Blynk, etc. I also do not want to send the notification directly from the Arduino, but rather from the PHP backend.
Can I send a FCM notification to my phone without having to create an app to receive it? I'm logged in with a Google/Gmail account on the phone, and I have no need to target any other users than myself.
Can I send a FCM notification to my phone without having to create an app to receive it?
No, this is not possible. It would open users up to some pretty hefty abuse.
In order to receive your notifications, the user must have your app installed.
Mind you, this can be a pretty minimal app, since the default implementation of FCM already displays notifications to the user if the app is not active. So really all you have to do is create an empty app that includes the Firebase Cloud Messaging SDK.

Getting "InvalidTokenFormat, Error 400" from Firebase Cloud Messaging

I am using Firebase Cloud Messaging for my android development with PHP as server side language. Right now, i'm able to :
Receive push notification sending using Firebase Console either both real apps and emulator.
Got it working when testing it out from terminal(curl)
So then, i tried sending from apps server(using php curl) instead of Firebase Console. And right now, encountered this weird message InvalidTokenFormat, Error 400 every time i'm request the POST request. Any thought?
Here is the link for Firebase Api were made : FirebaseApi Class
Feel free to ask for any inputs from meif above use case didn't clear enough. Thanks.
My mistake. The url should be(without slash at the end) :
https://fcm.googleapis.com/fcm/send
you need to send request to the firebase from your server with message of the notification and the token of the users then firebase will accept the request and broadcast the message to all the users (tokens that we provide) in form of a notification .
Firebase and device works on poll model, hence only firebase can send notification on your device , you can setup your poll with the device but google does not allow that because if each and every app starts to make a poll tunnel with the device , it will take up whole lot of resources.
Can you Post the raw request curl sends to the server? Normally curl does provide a printout for that, not sure about the php version.
CURLOPT_POSTFIELDS does not want a JSON. if you want to send a application/x-www-form-urlencoded request, use http_build_query($message) , or if you want to send a multipart/form-data request, give it the $message array directly.

How to send push notification by using php to android

I'm trying to send push notification to my app from PHP server.
but I don't understand certain thing like what I need to make PHP server.
I have my app. I configured every thing.
I have created my app in phonegap.
I have API KEY, Project NO., and Registration Key.
I have follow this articles:
Google Cloud Messaging GCM for Android and Push Notifications
Android Push Notifications using Google Cloud Messaging (GCM), PHP and MySQL
Push notifications with PhoneGap and Android
but still not able to create php page to send notifications.
I can send notification using pushbots.
but I want to create my own PHP page to send Push notification.
Please help me with this.
I will really appreciate your help.
Thanks in advance
For a good example of PHP code that send Android push notification look at this gist.
In order to have always the updated version of registration tokens, you should write another php page that receive tokens from devices and write them in a db. Then you can get these tokens before sending push notifications.

Sending notification to parse app through my localhost

Its my very first time in android and I'm making an application to receive notification and configured with parse notification.
Notifications are delivering successfully from their push notification portal.
I want to make it through my server.
Requirements are
I want to send notifications to all devices app installed on.
I want no expiry time.
I tried codes from google and stackoverflow but none of them delivered notification to my device, I'm trying this from localhost, so is there any need of being it on server like sending email needs it?
A good simple code is expected. Thank you guys :)

Push Notification using GCM - PHP

I am trying to implement Push Notification using GCM,
Besically i am trying to send Notification to the GCM using my PHP server which will deliver it to my android application.
I have used code at androidhive!
The device is getting registered successfully but i am not receiving any notification at my device nor anything is visible at Google console.
I am not receiving any response from the link used https://android.googleapis.com/gcm/send or https://android.googleapis.com
Is there anything wrong in this approach?
Can anyone suggest me any authentic source for this?
Realizing that some people are facing issues implementing GCM. I have decided to post solution.
The example on AndroidHive is working perfectly. Its just the matter of correct configuration.
Replace project ID in Android app. (You can get project ID from you google's console link i.e google.com/apis/console/#project:xxxxxxxxxxxx:access)
Replace Server API Key on PHP Server(config.php)
Key for server apps (with IP locking).
You can get your IP from WhatIsMyIP.
Key for browser apps (with referers) will not work.

Categories