Artdarek oauth-4-laravel/Lusitanian/PHPoAuthLib:发布LinkedIn共享API不起作用

Artdarek oauth-4-laravel/Lusitanian/PHPoAuthLib:发布LinkedIn共享API不起作用,oauth,linkedin,Oauth,Linkedin,我正在为我的最新项目使用。我可以用这个实现LinkedIn,但是发布共享不起作用。这是我的密码: $params['content'] =' <share> <comment>Check out the LinkedIn Share API!</comment> <content> <title>LinkedIn Developers Documentation On Using the Share API</title&

我正在为我的最新项目使用。我可以用这个实现LinkedIn,但是发布共享不起作用。这是我的密码:

$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 ));
但是这个帖子不起作用。但是我可以使用post,所以我认为我的访问令牌是可以的。这是我的cURL代码

$handle = curl_init();
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($handle, CURLOPT_URL, "https://api.linkedin.com/v1/groups/{$post->linkedInGroupAccount->linkedin_id}/posts?format=json&oauth2_access_token={$post->linkedInGroupAccount->access_token}");
curl_setopt($handle, CURLOPT_VERBOSE, TRUE);
$header[] = 'Content-Type: text/xml; charset=UTF-8';
curl_setopt($handle, CURLOPT_POSTFIELDS, $content);
curl_setopt($handle, CURLOPT_HTTPHEADER, $header);
$post->msg = curl_exec($handle);
curl_close($handle)
为什么$linkedinService->请求不起作用?

请尝试使用此代码 您的xml内容应该是这样的

$XML = "<share>
        <comment>This is a comment</comment>
        <content>
        <title>This is the title</title>
        <submitted-url>http://yourapp.dev</submitted-url>
        <submitted-image-url>http://yourapp.dev/image.jpg</submitted-image-url>
        <description>#riseofthetiger</description>
        </content>
        <visibility><code>anyone</code></visibility>
        </share>";
$headers = array(
            'Content-Type' => 'application/xml',
            'x-li-format' => 'xml',
        );
$result = json_decode( $linkedin->request('/people/~/shares?format=json', 'POST', $XML, $headers),true );
你的标题应该是这样的

$XML = "<share>
        <comment>This is a comment</comment>
        <content>
        <title>This is the title</title>
        <submitted-url>http://yourapp.dev</submitted-url>
        <submitted-image-url>http://yourapp.dev/image.jpg</submitted-image-url>
        <description>#riseofthetiger</description>
        </content>
        <visibility><code>anyone</code></visibility>
        </share>";
$headers = array(
            'Content-Type' => 'application/xml',
            'x-li-format' => 'xml',
        );
$result = json_decode( $linkedin->request('/people/~/shares?format=json', 'POST', $XML, $headers),true );
那就这样要求吧

$XML = "<share>
        <comment>This is a comment</comment>
        <content>
        <title>This is the title</title>
        <submitted-url>http://yourapp.dev</submitted-url>
        <submitted-image-url>http://yourapp.dev/image.jpg</submitted-image-url>
        <description>#riseofthetiger</description>
        </content>
        <visibility><code>anyone</code></visibility>
        </share>";
$headers = array(
            'Content-Type' => 'application/xml',
            'x-li-format' => 'xml',
        );
$result = json_decode( $linkedin->request('/people/~/shares?format=json', 'POST', $XML, $headers),true );

希望这能奏效

我不认为xml间距是个问题。因为我可以使用cURL发布相同的xml。我知道这已经有一段时间了,但是你解决过这个问题吗?如果是,如何解决?否,无法解决问题。