2013-07-10 91 views
0

我正在嘗試使用OAuth v2發佈分享給LinkedIn - 我已正確授權並擁有相應的訪問密鑰。LinkedIn使用RestClient共享API

發佈於:https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=(access令牌)

分享XML:

> <?xml version="1.0" encoding="UTF-8"?> <share> <content> <title>White 
> Cobalt Ltd</title> <description>Test</description> 
> <submitted-url>http://bit.ly/LpNpQH</submitted-url> </content> 
> <visibility> <code>anyone</code> </visibility> </share> 

代碼來郵(C#):

RestClient oRC = new RestClient(); 
RestRequest oRequest = new RestRequest(sURL, Method.POST); 
oRequest.AddHeader("Content-Type", "application/xml"); 
oRequest.AddHeader("x-li-format", "xml"); 
oRequest.RequestFormat = DataFormat.Xml; 
oRequest.AddBody(xml); 

RestResponse oResponse = (RestResponse)oRC.Execute(oRequest); 
if ((oResponse.ResponseStatus == ResponseStatus.Completed) && (oResponse.StatusCode == HttpStatusCode.Accepted)) 
{ 
... success 
} 

當我使用API​​控制檯(https://apigee.com/console/linkedin)它完美,但是當我嘗試通過代碼運行它(根據我可以判斷的完全相同的事情),我得到以下錯誤:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<error> 
<status>400</status> 
<timestamp>1373465292361</timestamp> 
<request-id>FQEJFQOL6U</request-id> 
<error-code>0</error-code> 
<message>Couldn't parse share document: error: The document is not a [email protected]://api.linkedin.com/v1: document element local name mismatch expected share got String</message> 
</error> 

幫助!

回答

0

我相信我找到了解決辦法 - 由於某種原因,LinkedIn API不喜歡的RESTClient實現功能:

oRequest.AddParameter("application/xml", sbXML.ToString(), ParameterType.RequestBody); 

的代碼開始工作:

oRequest.AddBody(xml); 

當我用它代替正確 - 必須以稍微不同的方式添加Post數據。

相關問題