Firebase Cloud Messaging example does not work

懵懂的女人 提交于 2021-01-29 09:30:22

问题


I am working through the tutorial on setting up Cloud Messaging. I followed the instructions in the video on the page https://firebase.google.com/docs/cloud-messaging/js/client?authuser=0 when I try to send the curl command I get a strange error. I have read the Cloud Messaging quickstart as well as a few other pages trying to solve the error, but to no avail.

The command I entered on the command line is:

curl --header "Authorization: key=AIzaSyCFCmFwwWV53PqV2M-NUZyp6lYSz43tUiQ" --header "Content-Type: application/json" -d '{"to": "di6GZyDevbI:APA91bFhNMiuJaMIE3IQL2NurPCWBhCtzculj5uvx-on121Z0UczJ0FyiiQbaRFvGqNs3bmq084vQ-z-8vF_GZQ5J-QCBrWgp4_saWSwTXytZmScNbPLGRkOQns_QgETStDTmLJwixI1", "notification": { "title": "Hello", "body": "World", "icon": "/firebase_logo.png" }}' https://fcm.googleapis.com/fcm/send

The result is:

curl: (3) Port number ended with 'A'
curl: (6) Could not resolve host: notification
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: title
curl: (6) Could not resolve host: Hello,
curl: (6) Could not resolve host: body
curl: (6) Could not resolve host: World,
curl: (6) Could not resolve host: icon
curl: (3) <url> malformed
curl: (3) [globbing] unmatched close brace/bracket in column 1
JSON_PARSING_ERROR: Unexpected character (') at position 0.

回答1:


The issue was with the quotes on the windows command line. After replacing the single quotes with double quotes and escaping the inner quotes it works, like so:

curl -X POST -H "Authorization: key=AAAAATYbVMw:APA91bFAEaRl8bZPgWGNGA7BCP22y_OLIlHevfUjEXEEklDav1sOwcxiFiFin625JsdaWJBAF06-U1Ey9-mhz6f2Es9-ztOeXpco6_AkvIbEO4dbe2LnI_JVw-W7mqOT5KeSn23y4b1h" -H "Content-Type: application/json" -d "{\"to\": \"di6GZyDevbI:APA91bFhNMiuJaMIE3IQL2NurPCWBhCtzculj5uvx-on121Z0UczJ0FyiiQbaRFvGqNs3bmq084vQ-z-8vF_GZQ5J-QCBrWgp4_saWSwTXytZmScNbPLGRkOQns_QgETStDTmLJwixI1\", \"notification\": { \"title\": \"Hello\", \"body\": \"World\", \"icon\": \"/firebase_logo.png\" }}" "https://fcm.googleapis.com/fcm/send"

Produces the expected result:

{"multicast_id":5167616001901538265,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1530306327290339%e609af1cf9fd7ecd"}]}


来源:https://stackoverflow.com/questions/51108902/firebase-cloud-messaging-example-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!