无法通过API发布到LinkedIn

时间:2016-02-18 15:02:44

标签: php api share linkedin posting

这是我的代码:

 $url = 'https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=XXXXXXX';
$url .= '&format=json';

    $postdata = http_build_query(
                                 array(
                                        'comment' => 'comment',
                                        'content' => array('title' => 'LInkedIN title',
                                                        'description' => 'linkedin desc',
                                                        'submitted-url' => "https://developer.linkedin.com",
                                                            ),

                                        'visibility' => array('code' => 'anyone')
                                    )
                                );

    $opts =     array('http' =>
                                            array('method' => 'POST',

                                            'header'=> "x-li-format : json\r\n".
                                            "Host: api.linkedin.com\r\n".
                                            "Content-Length: ".strlen($postdata)."\r\n".
                                            "X-Target-URI: https://api.linkedin.com\r\n".
                                            "Content-Type: application/json\r\n".
                                            "Connection: Keep-Alive",

                                            'content' => $postdata

                                            )                           
                                        );

$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);

但没有效果。试过这项服务https://apigee.com/console/linkedin - 完美地运作......

出了什么问题?

1 个答案:

答案 0 :(得分:0)

你想要建造什么? jssdk可以做得更好!看看我开发的这个工具:

http://datopstech.com/linkedin-share-tool/

和源代码:

https://github.com/kaburkett/LinkedIn-Advanced-Share

如果可以的话,请将您的项目作为基础。