Norlihazmey Ghazali
Norlihazmey Ghazali

Reputation: 9060

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 :

  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.

Upvotes: 2

Views: 1609

Answers (4)

hanshenrik
hanshenrik

Reputation: 21483

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.

Upvotes: 0

Hannes
Hannes

Reputation: 311

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.

Upvotes: 0

Norlihazmey Ghazali
Norlihazmey Ghazali

Reputation: 9060

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

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

Upvotes: 10

Rishabh Khanna
Rishabh Khanna

Reputation: 56

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.

Upvotes: 0

Related Questions