Linkedin API - OAuth.io

705 Views Asked by At

I'm developing an application that uses the Linkedin API. Php for the back-end. I used the library OAuth.io (SDK) and their service but I have a problem: I can't publish an update on linkedin. I used the syntax provided by SDK with the correct endpoint:

$request_object_li->post('/v1/people/~/shares?format=json', array('commment'=> 'Hello world!'));

I get this response:

Couldn't parse share document.
Unexpected element: CDATA.

According to the Linkedin's documentation I should include into the header these two lines:

Content-Type: application/json
x-li-format: json

How do I put them? The documentation of OAuth.io says nothing about. Someone has already worked with this library?

1

There are 1 best solutions below

4
On BEST ANSWER

As shown in https://github.com/oauth-io/sdk-php/blob/master/src/OAuth_io/RequestObject.php#L112, post takes a third parameter headers that can be leveraged as follows:

$request_object_li->post('/v1/people/~/shares?format=json', array('commment'=> 'Hello world!'), array('Content-Type'=>'application/json','x-li-format'=>'json');