POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1 Content-Type: application/json Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA { "message":{ "token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ", "data":{ "hello": "This is a Firebase Cloud Messaging device group message!" } } }
cURL 命令
curl-XPOST-H"Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA"-H"Content-Type: application/json"-d'{"message":{"data":{"hello":"This is a Firebase Cloud Messaging device group message!"},"token":"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ"}}'https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-16。"],[],[],null,["Device group messaging allows you to add multiple devices to a single group.\nThis is similar to topic messaging, but includes authentication to ensure that\ngroup membership is managed only by your servers. For example, if you want to\nsend different messages to different phone models, your servers can add/remove\nregistrations to the appropriate groups and send the appropriate message to each\ngroup. Device group messaging differs from topic messaging in that it involves\nmanaging device groups from your servers instead of directly within your\napplication.\n\nThe maximum number of members allowed for a notification key is 20.\n\nManaging device groups\n\n\nBefore sending messages to a device group, you must:\n\n1.\n Obtain registration tokens for each device you want to add\n to the group.\n\n2.\n Create the `notification_key`, which identifies\n the device group by mapping a particular group (typically a\n user) to all of the group's associated registration tokens.\n You can create notification keys on the app server.\n\n\nBasic management of device groups --- creating and removing groups,\nand adding or removing devices --- is performed via the HTTP v1 API,\nusing short-lived tokens to\n[authorize send requests](/docs/cloud-messaging/auth-server).\nSee [Device group management keys](#device-group-management-keys) for a list of supported keys.\n\nManaging device groups on the app server\n\nCreating a device group\n\n\nTo create a device group, send a POST request that provides a name\nfor the group, and a list of registration tokens for the devices.\nFCM returns a new `notification_key`\nthat represents the device group.\n\n**HTTP POST request**\n\n\nSend a request like the following to\n`https://fcm.googleapis.com/fcm/notification`: \n\n```c++\nhttps://fcm.googleapis.com/fcm/notification\nContent-Type:application/json\naccess_token_auth: true\nAuthorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA\nproject_id:SENDER_ID\n\n{\n \"operation\": \"create\",\n \"notification_key_name\": \"appUser-Chris\",\n \"registration_ids\": [\"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...\",\n \"cR1rjyj4_Kc:APA91bGusqbypSuMdsh7jSNrW4nzsM...\",\n ... ]\n```\n\n\nThe `notification_key_name` is a name or identifier\n(e.g., it can be a username) that is unique to a given group. The\n`notification_key_name` and\n`notification_key` are unique to a group of registration\ntokens. It is important that `notification_key_name` is\nunique per client app if you have multiple client apps for the same\n[sender ID](/docs/cloud-messaging/concept-options#senderid).\nThis ensures that messages only go to the intended target app.\n\n**Response format**\n\nA successful request returns a `notification_key` like\nthe following: \n\n```c++\n{\n \"notification_key\": \"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ\"\n}\n```\n\n\nSave the `notification_key` and the corresponding\n`notification_key_name` to use in subsequent operations.\n| Invalid registration tokens are dropped when a device group is successfully created.\n\nRetrieving a notification key\n\n\nIf you need to retrieve an existing notification key, use the\n`notification_key_name` in a GET request as shown: \n\n```c++\nhttps://fcm.googleapis.com/fcm/notification?notification_key_name=appUser-Chris\nContent-Type:application/json\naccess_token_auth: true\nAuthorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA\nproject_id:SENDER_ID\n{}\n```\n\nFor each GET request for a given notification key name, the server\nreturns a unique encoded string. Though each string may appear to be\na different key, it is actually a valid \\`notification_key\\` value.\n\nAdding and removing devices from a device group\n\n\nTo add or remove devices from an existing group, send a POST\nrequest with the `operation` parameter set to\n`add` or `remove`, and provide the\nregistration tokens for addition or removal.\n| If you remove all existing registration tokens from a device group, FCM deletes the device group.\n\n**HTTP POST request**\n\nFor example, to add a\ndevice with the registration token `bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...`\nto `appUser-Chris`, you would send this request: \n\n {\n \"operation\": \"add\",\n \"notification_key_name\": \"appUser-Chris\",\n \"notification_key\": \"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ\",\n \"registration_ids\": [\"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...\"]\n }\n\n**Response format**\n\nA successful request to either add or remove a device returns a\n`notification_key` like the following: \n\n```c++\n{\n \"notification_key\": \"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ\"\n}\n```\n| **Note:** `notification_key_name` is not required for adding/removing registration tokens, but including it protects you against accidentally using the incorrect `notification_key`.\n\nDevice group management keys\n\nThe following table lists the keys for creating device groups\nand adding and removing members.\n\n\n**Table 10.** Device group management keys.\n\n| Parameter | Usage | Description |\n|-------------------------|-------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `operation` | Required, string | The operation to run.Valid values are `create`, `add`, and `remove`. |\n| `notification_key_name` | Required, string | The user-defined name of the device group to create or modify. |\n| `notification_key` | Required (except for `create` operation, string | Unique identifier of the device group. This value is returned in the response for a successful `create` operation, and is required for all subsequent operations on the device group. |\n| `registration_ids` | Required, array of strings | The device tokens to add or remove. If you remove all existing registration tokens from a device group, FCM deletes the device group. |\n\nSending downstream messages to device groups\n\nSending messages to a device group is very similar to sending\nmessages to an individual device, using the same method to\n[authorize send requests](/docs/cloud-messaging/auth-server). Set the `token`\nfield to the group notification key: \n\nREST \n\n POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1\n\n Content-Type: application/json\n Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA\n\n {\n \"message\":{\n \"token\":\"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ\",\n \"data\":{\n \"hello\": \"This is a Firebase Cloud Messaging device group message!\"\n }\n }\n }\n\ncURL command \n\n curl -X POST -H \"Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA\" -H \"Content-Type: application/json\" -d '{\n \"message\":{\n \"data\":{\n \"hello\": \"This is a Firebase Cloud Messaging device group message!\"\n },\n \"token\":\"APA91bGHXQBB...9QgnYOEURwm0I3lmyqzk2TXQ\"\n }}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send\n\n| **Note:** Unlike the device group send methods in deprecated legacy APIs, the HTTP v1 response does not contain success and failure counts. A successful send returns an empty response."]]