FCM -编程发送推送通知给用户段[重复]

时间:2021-05-23 16:22:46

This question already has an answer here:

这个问题已经有了答案:

I am able to send the notification to single device, topics and user segment from Firebase Console.

我能够将通知从Firebase控制台发送到单个设备、主题和用户段。

I want to send the push notification to a user segment. I searched a lot but I'm only getting script to send notification to Single User or Topic not to user segments.

我想把推送通知发送给用户段。我搜索了很多,但是我只得到了一个脚本,将通知发送给单个用户或主题,而不是发送给用户段。

I tried the below code

我尝试了下面的代码

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); 

And i am getting the response below

下面是我的回答。

{"multicast_id":5837227475989925972,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

1 个解决方案

#1


9  

Unfortunately, it seems that sending to user segments programatically still isn't possible. Reference here:

不幸的是,以编程方式发送给用户段似乎仍然是不可能的。参考这里:

But you won't be able to

但你做不到

  1. send notifications to a Firebase User Identifier (UID) and

    将通知发送到Firebase用户标识符(UID)和

  2. send notifications to user segments (targeting properties & events like you can on the user console).

    向用户段发送通知(针对属性和事件,就像您在用户控制台中所做的那样)。

It's only possible via the Firebase Console.

这只能通过Firebase控制台实现。

#1


9  

Unfortunately, it seems that sending to user segments programatically still isn't possible. Reference here:

不幸的是,以编程方式发送给用户段似乎仍然是不可能的。参考这里:

But you won't be able to

但你做不到

  1. send notifications to a Firebase User Identifier (UID) and

    将通知发送到Firebase用户标识符(UID)和

  2. send notifications to user segments (targeting properties & events like you can on the user console).

    向用户段发送通知(针对属性和事件,就像您在用户控制台中所做的那样)。

It's only possible via the Firebase Console.

这只能通过Firebase控制台实现。