artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
683 stars 216 forks source link

Linkedin Share Api not working #33

Open zakir-hyder opened 10 years ago

zakir-hyder commented 10 years ago

I am trying to post status in Linkedin . Here is my code

$params['content'] ='
<share>
    <comment>Check out the LinkedIn Share API!</comment>
    <content>
        <title>LinkedIn Developers Documentation On Using the Share API</title><description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description>
        <submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url>
        <submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url>
    </content>
    <visibility>
        <code>connections-only</code>
    </visibility>
</share>';

$extraHeaders = array(
  'Content-type' =>  'application/xml',
);
$status = json_decode($linkedinService->request('people/~/shares?format=json' , 'POST' , $params , $extraHeaders ));

I can post using curl with the same access_token. So I am not sure what I am doing wrong.

ndamnjanovic commented 9 years ago

Hey @zakir-hyder , did you manage to make it work? I'm able to GET, but not to POST.

zakir-hyder commented 9 years ago

@ndamnjanovic i could not make it work. I used curl instead.

ndamnjanovic commented 9 years ago

@zakir-hyder ok, thanks for response!

elegisandi commented 9 years ago

@zakir-hyder $params doesn't need to be an array, just a string variable will do. You may use the json format also ( i prefer it on my end ).

$share = array( 'comment' => 'YOUR COMMENT GOES HERE' 'content' => array( 'title' => 'CONTENT TITLE GOES HERE', 'submittedUrl' => 'CONTENT URL GOES HERE', 'submittedImageUrl' => 'CONTENT IMAGE URL GOES HERE' ), 'visibility' => array( 'code' => 'anyone' ) );

$headers = array( 'Content-Type' => 'application/json' );

$result = (array) simplexml_load_string($linkedin_service->request('https://api.linkedin.com/v1/people/~/shares', 'POST', json_encode($share), $headers));

if(isset($result['update-key']) && isset($result['update-url'])) return true; else return false;

PS: The response is always in xml format. Your request content type (xml or json) doesn't matter anymore.

zakir-hyder commented 9 years ago

@elegisandi i will check. have you successfully shared with application/json content type? I tried to share with application/json last january. it did not work.

elegisandi commented 9 years ago

@zakir-hyder yes it is working on my end. actually im using this one in my current project :) just make sure you have an access token :D

sergiuseg commented 9 years ago

Hi Guys, I used LinkedIn API for posting, but posts not show on timeline, only on user activity, why It so

carlxaeron commented 9 years ago

Hi. My problem is $linkedinService = OAuth::consumer( 'Linkedin' ); $share = array( 'comment' => Input::get('content'), 'content' => array( 'title' => 'LinkedIn Developers Resources', 'description' => 'Leverage LinkedIn\'s APIs to maximize engagement', 'submitted-url' => 'https://developer.linkedin.com', 'submitted-image-url' => 'https://example.com/logo.png' ), 'visibility' => array( 'code' => 'anyone' ) );

    $headers = array(
        'Content-Type' => 'application/json',
        'x-li-format' => 'json',
    );

    $result = json_decode( $linkedinService->request('/people/~/shares?format=json', 'POST', json_encode($share), $headers),true );

in linkedin the sharing is successful but in my return in codes it is always returning a tokenresponseexception

elegisandi commented 9 years ago

@sergiuseg are you referring to linkedin share? if so, you must use this url, https://api.linkedin.com/v1/people/~/shares, in your request.

elegisandi commented 9 years ago

@carlxaeron 'submitted-url' and 'submitted-image-url' must be in camel-cased, see my comment above or click this link (https://github.com/artdarek/oauth-4-laravel/issues/33#issuecomment-65385782). if still ain't working, please comment the Exception on this thread.