使用Firebase(FCM)在Android设备上发送推送通知



我正在尝试在C#.NET中使用FCM在Android设备上发送推送通知,但是我收到" InvalidRegrigration"错误消息。

我也从Postman和R-Client中使用了相同的错误,但仍然遇到同样的错误。

   public String SendNotificationFromFirebaseCloud()
    {
        string DeviceToken = "RegToken";           
        string YOUR_FIREBASE_SERVER_KEY = "ServerKey";
        var result = "-1";
        var webAddr = "https://fcm.googleapis.com/fcm/send";
        var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.Headers.Add("Authorization:key=" + YOUR_FIREBASE_SERVER_KEY);
        httpWebRequest.Headers.Add(string.Format("Sender: id={0}", "MySenderId"));
        httpWebRequest.Method = "POST";
        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = "{"to":"" + DeviceToken + "","data":{"message": "Welcome"}}";               
            streamWriter.Write(json);
            streamWriter.Flush();
        }
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            result = streamReader.ReadToEnd();
        }
        return result;
    }

{" MultiCast_Id":86714095063578777791,"成功":0,"失败":1," Canonical_ids":0,"结果"," error":[{"错误":" InvalidRegation"}}}}}

"无效的注册"表示设备令牌不正确,没有指向现有设备。

介意,这并不意味着已关闭的设备,这意味着根本没有设备(当前(使用该令牌。

换句话说,这是一个不良收件人地址的指示,实际上是http 404错误的等同。

相关内容

  • 没有找到相关文章

最新更新