我正在尝试弄清楚如何使用Firebase向Android发送推送通知,并使用旧版HTTP(https://fcm.googleapis.com/fcm/send)使其工作,但文档建议使用较新的 endpoints (https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send) . 我似乎无法让它工作,因为我一直得到这样的回应:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
使用https://firebase.google.com/docs/cloud-messaging/send-message#send_messages_to_specific_devices处的示例会发生这种情况:
POST https://fcm.googleapis.com/v1/projects/project-916177026973/messages:send HTTP/1.1
cache-control: no-cache
Postman-Token: 81403929-77ba-4568-8681-a854527ccb22
Content-Type: application/json
Authorization: Bearer <token redacted>
User-Agent: PostmanRuntime/6.4.1
Accept: */*
Host: fcm.googleapis.com
accept-encoding: gzip, deflate
content-length: 319
Connection: close
{
"message":{
"token" : <token redacted>,
"notification" : {
"body" : "This is an FCM notification message!",
"title" : "FCM Message",
}
}
}
我还尝试删除最后一个逗号以使其符合JSON并仍然没有运气 . 有任何想法吗?
1 回答
正如OP指出Firebase现在建议FCM v1 endpoints ,如果你想通过HTTP发送消息 .
它看起来像这样:
URL
your_project_id_here
的部分是 your 项目ID . 您需要在选项卡General
下找到项目特定的项目project Id
,该项目位于Firebase控制台的Settings
部分 .寻找
Project ID
. 如果您对正确的Project ID
有任何疑问,如果网站中的URL指向您的项目,它也是一个部分 . 看起来像: