0

yesterday I implemented an Android test app on basis of Google's quickstart sample. Sending notifications using the Firebase console worked immediately. But now I want to send a notification using curl. I tried

curl -X POST --header "Authorization:key=AIzaSyAt-ZnG3..." --header "Content-Type:application/json" https://fcm.googleapis.com/fcm/send -d "{\"anydata\" : \"blabla\"}"

I always get an Error 401 = Unauthorized as response.

In other questions I read something about a server key which I cannot find anywhere. I use the api key out of the provided google-services.json file.

I also added a space character between 'Authorization:' and 'key' and tried many other things I don't remember.

Questions:

  • Do I have to enable anything in Firebase's console?
  • Is there a problem with the quotes in the curl statement in Linux? Maybe they are removed by the shell before sending?
  • Anything else?

Please help me, otherwise I have to investigate for an alterative push notification provider and learning starts again, but I have no time left anymore.

Kind regards, Uwe

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Guzzer
  • 161
  • 5
  • You need the **server** key. See here how to find it: http://stackoverflow.com/questions/37427709/firebase-messaging-where-to-get-server-key – Frank van Puffelen Sep 18 '16 at 14:36
  • Many thanks for the link. The api key provided in google-services.json file is not equal to the server key to be used. Where to find the server key is described in mentioned article http://stackoverflow.com/questions/37427709/firebase-messaging-where-to-get-server-key . Now it seems to work. – Guzzer Sep 18 '16 at 19:01
  • the google-services.json contains values that you can safely use in your app code. The **server** key is indeed not part of google-services.json, because it should never be used from within your app. – Frank van Puffelen Sep 18 '16 at 22:49
  • Unfortunately it doesn't work. I use the follwoing command curl --header "Authorization:key=AIzaSy..." --header "Content-Type:application/json" https://fcm.googleapis.com/fcm/send -d "{ \"to:\" \"/topics/news\", \"data\": { \"message\": \"This is a Firebase Cloud Messaging Topic Message!\"}}" to send to topic 'news'. Using the firebase console works but using curl I get the simple response 'to'. Only this single word. What's wrong? – Guzzer Sep 19 '16 at 16:46
  • One step further: I had to use \"to\": instead of \"to:\" . Now I get a message ID as response. But the app doesn't receive the message. Using the firebase console it does. Can anybody help me? – Guzzer Sep 19 '16 at 17:08

0 Answers0