0

过去一周我一直在努力在 LinkedIn 中添加评论,但我还没有得到解决方案

protected void Page_Load(object sender, EventArgs e)
{
    string ConsumerKey = "**********";
    string ConsumerSecret = "**********";
    string Token = "**********";
    string TokenSecret = "**********";

    string xmlContent = "<?xml version='1.0' encoding='UTF-8'?>" + Environment.NewLine +
        "<comment>" + Environment.NewLine +
        "<text>Check out</text>" + Environment.NewLine +
        "</comment>";
    byte[] dataBytes = Encoding.Default.GetBytes(xmlContent);

    var postData = new Dictionary<string, string>()
    {
        {"key1","value1"}
    };
   String requestUrl = "http://api.linkedin.com/v1/posts/{post-id}/comments?oauth_token=" + Token;

    RestClient rc = new RestClient();
    RestRequest request = new RestRequest(requestUrl, Method.POST);
    request.AddHeader("Content-Type", "application/xml");
    request.AddHeader("x-li-format", "xml");

    request.RequestFormat = DataFormat.Xml;
    request.AddBody(xmlContent);

    RestResponse restResponse = (RestResponse)rc.Execute(request);
    ResponseStatus responseStatus = restResponse.ResponseStatus;
}

我收到一个错误

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
 <error>
     <status>401</status> 
     <timestamp>1375175962003</timestamp> 
     <request-id>10K340J5W6</request-id> 
     <error-code>0</error-code> 
     <message>[unauthorized]. ssl_required</message> 
 </error>

我想要解决方案。提前致谢。

4

1 回答 1

0

我可以看出两件事不对。

  1. 该错误表明您需要使用 ssl (ssl_required),因此 url 应该是 'String requestUrl = " https://api.linkedin ...' 而不是 'String requestUrl = " http://api.linkedin ...'

  2. restSharp.AddBody 会对对象进行编码,相信你需要使用

    request.AddParameter("text/xml", xmlContent, ParameterType.RequestBody); 
    

    而不是

     request.AddBody(xmlContent); 
    

    线。

于 2014-05-07T13:48:17.000 回答