0

我正在尝试使用 OAuth v2 向 LinkedIn 发布共享 - 我已正确获得授权并拥有适当的访问密钥。

发布到:https ://api.linkedin.com/v1/people/~/shares?oauth2_access_token=(访问令牌)

共享 XML:

> <?xml version="1.0" encoding="UTF-8"?> <share> <content> <title>White
> Cobalt Ltd</title> <description>Test</description>
> <submitted-url>https://www.whitecobalt.com/</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 share@http://api.linkedin.com/v1: document element local name mismatch expected share got String</message>
</error>
4

1 回答 1

0

我相信我找到了解决方案——出于某种原因,LinkedIn API 不喜欢 RestClient 函数:

oRequest.AddBody(xml); 

当我将其替换为:

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

代码开始正常工作 - 必须以稍微不同的方式添加 Post 数据。

于 2013-07-10T16:15:50.003 回答