2

I am using Firebase Cloud Messaging for my android development with PHP as server side language. Right now, i'm able to :

  1. Receive push notification sending using Firebase Console either both real apps and emulator.

  2. 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.

8
  • Maybe you are missing something in php curl! (AutorizationToken) ?! Jul 30, 2016 at 22:31
  • @IsmailRBOUH you meant Authorization: key=some keys header? Jul 30, 2016 at 22:32
  • Yes something similar could you please add your curl request ? Jul 30, 2016 at 22:33
  • @IsmailRBOUH everything inside FirebaseApi Class - pastebin.com/sk72Czz8 file. The curl code inside init() method body. To make a request, i just initiated FirebaseApi class and call init() method Jul 30, 2016 at 22:36
  • Make sure you are using the SERVER KEY in your PHP code, not your Android key Jul 30, 2016 at 23:25

4 Answers 4

10

My mistake. The url should be(without slash at the end) :

https://fcm.googleapis.com/fcm/send
0

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.

0
0

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.

0
0

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.

2
  • Indeed, but in FCM case, it does need for application/json header along with json data as i choose application/json instead of text Aug 1, 2016 at 14:51
  • @NorlihazmeyGhazali oh, then i think you're supposed to use CURLOPT_INFILE / CURLOPT_READFUNCTION , not CURLOPT_POSTFIELDS
    – hanshenrik
    Aug 1, 2016 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.