FCM - 以编程方式向用户群发送推送通知
FCM - Programmatically Send Push Notification To User Segments
我可以从 Firebase 控制台向单个设备、主题和用户群发送通知。
我想将推送通知发送到用户群。我搜索了很多,但我只得到脚本来向单个用户或主题发送通知,而不是向用户群发送通知。
我尝试了下面的代码
var client = new RestClient("https://fcm.googleapis.com/fcm/send");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "key=mykey");
request.AddParameter("application/json", "\n\n{\"to\" : \"user-segment-name\",\n\"notification\" : {\n \"body\" : \"test message\",\n \"title\" : \"Portugal vs. Denmark\"\n },\n \"priority\":\"high\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Response.Write(response.Content);
我收到以下回复
{"multicast_id":5837227475989925972,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
不幸的是,似乎仍然无法以编程方式发送给用户段。参考:
But you won't be able to
send notifications to a Firebase User Identifier (UID) and
send notifications to user segments (targeting properties & events like you can on the user console).
只能通过 Firebase 控制台实现。
我可以从 Firebase 控制台向单个设备、主题和用户群发送通知。
我想将推送通知发送到用户群。我搜索了很多,但我只得到脚本来向单个用户或主题发送通知,而不是向用户群发送通知。
我尝试了下面的代码
var client = new RestClient("https://fcm.googleapis.com/fcm/send");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "key=mykey");
request.AddParameter("application/json", "\n\n{\"to\" : \"user-segment-name\",\n\"notification\" : {\n \"body\" : \"test message\",\n \"title\" : \"Portugal vs. Denmark\"\n },\n \"priority\":\"high\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Response.Write(response.Content);
我收到以下回复
{"multicast_id":5837227475989925972,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
不幸的是,似乎仍然无法以编程方式发送给用户段。参考
But you won't be able to
send notifications to a Firebase User Identifier (UID) and
send notifications to user segments (targeting properties & events like you can on the user console).
只能通过 Firebase 控制台实现。