2014-02-06 71 views
1

我想從WCF休息服務向Kindle Fire發送推送通知。如何通過WCF休息服務向Kindle Fire發送推送通知

我使用PushSharp庫,但它不能正常工作。你能不能使用PushSharp庫建議任何其他方式?

我使用下面的代碼到Kindle上發送通知是給錯誤400,

private void sendNotification(String registrationID) 
    { 
     String message = "{data\": {\"NTY\":\"-1\",\"NOTY\": \"2\"}}"; 
     String title="title"; 

     String accessToken = ""; 
     accessToken = UpdateAccessToken(); 
     HttpWebRequest httpWReq = 
      (HttpWebRequest)WebRequest.Create("https://api.amazon.com/messaging/registrations/" + registrationID + "/messages"); 

     Encoding encoding = new UTF8Encoding(); 
     string postData = "{\"data\":{\"message\":\"" + message + "\",\"title\":\"" + title + "\"},\"consolidationKey\":\"Some Key\",\"expiresAfter\":86400}"; 
     byte[] data = encoding.GetBytes(postData); 

     httpWReq.ProtocolVersion = HttpVersion.Version11; 
     httpWReq.Method = "POST"; 
     httpWReq.ContentType = "application/json";//charset=UTF-8"; 
     httpWReq.Headers.Add("X-Amzn-Type-Version", 
              "[email protected]"); 
     httpWReq.Headers.Add("X-Amzn-Accept-Type", 
             "[email protected]"); 
     httpWReq.Headers.Add(HttpRequestHeader.Authorization, 
      "Bearer " + accessToken); 
     httpWReq.ContentLength = data.Length; 


     Stream stream = httpWReq.GetRequestStream(); 
     stream.Write(data, 0, data.Length); 
     stream.Close(); 

     HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse(); 
     string s = response.ToString(); 
     StreamReader reader = new StreamReader(response.GetResponseStream()); 
     String jsonresponse = ""; 
     String temp = null; 
     while ((temp = reader.ReadLine()) != null) 
     { 
      jsonresponse += temp; 
     } 

    } 

回答

2

PushSharp依賴於谷歌雲端通訊爲Android,這是不支持的Kindle。你會需要或者實施亞馬遜設備消息(ADM)版本(https://developer.amazon.com/public/apis/engage/device-messaging)或利用亞馬遜的簡單通知服務(SNS)的目標Kindle和其他平臺(https://aws.amazon.com/sns/

+0

謝謝,它的使用完全可以你給我它實現的代碼示例? – aemie

+0

亞馬遜網站有一個很好的演練來實現這 – Offbeatmammal

+0

我讀過它,但我不明白我如何使用它,我嘗試了一些東西,但它不工作。我也發郵件給亞馬遜支持團隊,但他們沒有回覆。我可以給我代碼示例。 – aemie