2014-01-27 46 views
0

我嘗試在我的MVC 4應用程序中使用Hammock庫函數調用共享REST API。無法解析共享文檔:LinkedIn中的錯誤REST API共享

請參考下面

public ActionResult SharePost() 
    { 
     string content = ""; 
     try 
     { 
      var credentials = new OAuthCredentials 
      { 
       ConsumerKey = "xxxxxxxxxxxxxx", 
       ConsumerSecret = "xxxxxxxxxxxxxxxx", 
       Token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
       TokenSecret = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
       Verifier = verifier, 
       Type = OAuthType.AccessToken, 
       ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader, 
       SignatureMethod = OAuthSignatureMethod.HmacSha1, 
       Version = "1.0" 
      }; 

      var client = new RestClient { Authority = "http://api.linkedin.com/v1", Credentials = credentials, Method = WebMethod.Post }; 
      var request = new RestRequest { Path = "/people/~/shares" }; 

      StringBuilder sbAppend = new StringBuilder(); 
      sbAppend.AppendLine("<?xml version=1.0 encoding=UTF-8?>"); 
      sbAppend.AppendLine("<share><comment>Check out the LinkedIn Share API!</comment><content><title>LinkedIn Developers Documentation On Using the Share API</title><description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description><submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url><submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url></content><visibility><code>anyone</code></visibility></share>"); 

      client.AddHeader("Content-Type", "text/xml"); 

      byte[] msg = Encoding.Default.GetBytes(sbAppend.ToString()); 
      client.AddPostContent(msg); 

      RestResponse response = client.Request(request); 
      content = response.Content; 

     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
     return Content(content); 
    } 

我的代碼,但我得到一個錯誤responce.content

enter image description here

編輯

我在XML頭使用雙引號。但始終顯示相同的錯誤。

enter image description here

有什麼事情不對。

我沒有在fiddller中看到後期的xml值。請參閱此影像

enter image description here

請幫助。

回答

1

我發現錯誤在你的XML你缺少「」 試試這個

sbAppend.AppendLine('<?xml version="1.0" encoding="UTF-8"?>'); 
+0

謝謝您的寶貴答覆。但我alredy使用這個雙引號。但我得到同樣的錯誤。 –