2016-12-02 16 views
0

FCMを使用してAndroidにプッシュ通知を送信し、C#で実装したいと考えています。FCM(c#)を使用してAndroidにプッシュ通知

私は以下のコードを使用していますが、それは私のIDがすべてOKです。

しかし、デバイスIDが正しいため、デバイスに通知が届かず、FCMコンソールから送信すると通知が届きませんでした。

いずれかの提案が役立ちます。

おかげ

var value = "This is first message to Android"; 
      WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send"); 
      tRequest.Method = "post"; 
      tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; 
      tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAAosN-NoU:APA91bHg6Iv8qj2giVvSRVVFze4L6Si0VTwctkNaRRqlI7qffKAMPHo4fd52SgZcB8Ring-mnPrkqjodTGrSru_bXKRQD9n4eVxhs8pTbkXac1gotCM77EixMUXTplXhceIm1o20BVXvkHO1HQZBti990ijebUW1fg")); 
      tRequest.Headers.Add(string.Format("Sender: id={0}", "699064530565")); 

      string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + "APA91bFD6jRdsSzQ37_rB2x4C8wJzcDzgdjZuhf4hFgzCndeESCEnHrW3sRQcwetljExhlEUrpquhdTW2C24qjtb-PJuUUhpnev3Zn_DDH6aF7PStFRPYvWSQcfLFd14sueLmbhCvcqr" + ""; 

      Byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
      tRequest.ContentLength = byteArray.Length; 

      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 sResponseFromServer = tReader.ReadToEnd(); 
         } 
        } 
       } 
      } 
+0

誰も知りません....私は自分自身を解決します – user2412197

+0

あなたのPostDataを見て、デバッグ後に正確なエラーを共有してください。 –

答えて

0

あなたのPostDataのに見てください。データの書式設定の例を次に示します。

var PostData= new 

      { 
       data = {your custom data you want to send}, 
       to = deviceId, 

       notification = new 

       { 

        body = "Got notify", 

        title = Alert, 

       }, 
       priority ="normal" 
      }; 

      var serializer = new JavaScriptSerializer(); 

      var json = serializer.Serialize(PostData); 

      Byte[] byteArray = Encoding.UTF8.GetBytes(json); 

コードをデバッグして正確なエラーを共有してください。まあうまくいけばコードの上に問題を解決してください。

関連する問題