0

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?

Claudio
  • 45
  • 1
  • 1
  • 9

1 Answers1

1

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');
Hans Z.
  • 50,496
  • 12
  • 102
  • 115
  • The ?format=json URL argument instructs LinkedIn's API to return the results of a particular call in JSON format. Both header values are required when sending data in to LinkedIn. – Justin Kominar Mar 30 '15 at 16:26
  • no, see: https://developer.linkedin.com/docs/rest-api which says: `If it is more convienent for your application to work with data in JSON format, you can request that APIs return you JSON data using one of the following methods: 1. Add a format=json URL argument to the end of your API call. 2. Add this HTTP header to your API call: x-li-format: json` – Hans Z. Mar 30 '15 at 16:32
  • I wrote those docs :) Apologies if it's unclear, however the intent was that if you are requesting data from the API, you/docs are correct ... either will do. If you are *sending* data to LinkedIn in JSON format, both header values are required. – Justin Kominar Mar 30 '15 at 21:43
  • ok, I don't follow the logic, nor do I think the docs reflect it, but I've modified the answer.. – Hans Z. Mar 31 '15 at 05:58