Я пытаюсь создать новую группу устройств в Firebase, как описано здесь , но я всегда получаю в ответ «400 неверных запросов», но я не знаю почему.
Это функция создания группы устройств:
private static string CreateNotificationGeoup(string notificationKey, string[] registrationIds, string serverKey, string senderId)
{
var notificationGroup = new
{
operation = "create",
notification_key_name = notificationKey,
registration_ids = registrationIds
};
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/notification");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
string jsonNotificationFormat = JsonConvert.SerializeObject(notificationGroup);
Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat);
tRequest.Headers.Add(string.Format("Authorization: key={0}", serverKey));
// tRequest.Headers.Add(HttpRequestHeader.Authorization, "key=" + serverKey);
tRequest.Headers.Add("project_id", senderId);
tRequest.ContentLength = byteArray.Length;
tRequest.ContentType = "application/json";
try
{
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String responseFromFirebaseServer = tReader.ReadToEnd();
var jsondata = JObject.Parse(responseFromFirebaseServer);
return jsondata["notification_key"].ToString();
}
}
}
}
}
catch (FCMException e)
{
throw e;
}
}
и это объект Json после сериализации:
{"operation":"create","notification_key_name":"30042","registration_ids":["user_78"]}