Pregunta

I am trying to post a Share to LinkedIn using OAuth v2 - I have got authorisation correctly and have the appropriate access keys.

Posting to: https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=(access token)

Share 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>

Code to Post (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
}

When I use the API Console (https://apigee.com/console/linkedin) it works perfectly, but when I try to run it through the code (which as far as I can tell is doing exactly the same thing) I get the following error:

<?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>
¿Fue útil?

Solución

I believe I found the solution - for some reason the LinkedIn API doesn't like the RestClient function:

oRequest.AddBody(xml); 

When I replaced it with:

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

The code started to work correctly - must be adding the Post data in a slightly different way.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top