ashwinks / PHP-LinkedIn-SDK

A PHP wrapper for the LinkedIn API
94 stars 74 forks source link

Can't post to Share API #7

Closed markopavlovic closed 9 years ago

markopavlovic commented 10 years ago

First of all great work! Somehow I can't get Share API to work with this.

I tried multiple parameter types and I always get this.

[errorCode] => 0
    [message] => Invalid xml {Expected elements 'post-network-update@http://api.linkedin.com/v1 id@http://api.linkedin.com/v1 visibility@http://api.linkedin.com/v1 ad-account@http://api.linkedin.com/v1 comment@http://api.linkedin.com/v1 attribution@http://api.linkedin.com/v1 mention@http://api.linkedin.com/v1 private-message@http://api.linkedin.com/v1 share-target-reach@http://api.linkedin.com/v1' instead of 'visibilty@http://api.linkedin.com/v1' here in element share@http://api.linkedin.com/v1}
    [requestId] => NC50O2WKV9
    [status] => 400
    [timestamp] => 1397323889255

This is how I set my $payload when doing a post request with php $this->LinkedIn->post($endpoint, $payload);

Array
(
    [comment] => 20+ Awesome Ways to Get More Followers for Your Google Plus Business Page - http://blog.kissmetrics.com/get-more-google-plus-followers/
    [content] => Array
        (
            [submitted-url] => http://blog.kissmetrics.com/get-more-google-plus-followers/
            [title] => Test
        )

    [visibilty] => Array
        (
            [code] => anyone
        )

)

The problem is not with auth. token, since I never get an error around that and I have pre-called php $this->LinkedIn->setAccessToken($creds['token']);.

Any guess on what it could be, is my $payload structured wrong? I gone over and over through Linkedins Share API docs, but I just don't see anything I could miss.

Thanks

phpsa commented 10 years ago

Works for me: used the following php code: $post = array( 'comment' => 'Test social Share', 'content' => array( 'title' => 'Test Title', 'description' => 'test description', //Maxlen(255) 'submitted_url' => 'http://rankedbyreview.co.nz' ), 'visibility' => array( 'code' => 'anyone' )

    );
    $post = $li->post('people/~/shares', $post);
godlyfast commented 9 years ago

$headers[] = 'x-li-format: json';

muhammad-khalid commented 9 years ago

Solution of phpsa works fine.

marceloj commented 9 years ago

Perfect PHPSA !! TK

$json = array( 'comment' => 'Test social Share', 'content' => array( 'title' => 'Test Title', 'description' => 'test description', //Maxlen(255) 'submitted_url' => 'http://rankedbyreview.co.nz' ), 'visibility' => array( 'code' => 'anyone' ));

$post = $li->post('/people/~/shares', $json);