我正在使用https://github.com/artdarek/oauth-4-laravel作为我的最新项目。我能够使用这个来实现LinkedIn OAuth,但是发布份额不起作用。这是我的代码:
$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 ));
但这张贴不起作用。但我可以使用cURL发帖,所以我认为我的access_token没问题。这是我的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-&gt; request()不起作用?
答案 0 :(得分:0)
尝试使用此代码 你的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 );
希望有效