2014-01-31 30 views
1

我正在爲我的最新項目使用https://github.com/artdarek/oauth-4-laravel。我能夠使用此工具實現LinkedIn OAuth,但發佈共享不起作用。這裏是我的代碼:Artdarek oauth-4-laravel/Lusitanian/PHPoAuthLib:張貼LinkedIn共享API不工作

$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-> request()不起作用?

+0

我知道這已經有一段時間了,但是你有沒有解決過這個問題?如果是,如何? – ericbae

回答

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>"; 

和你的頭想這

​​

然後要求這樣

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

希望工作

+0

你有沒有試過這段代碼? –

+0

是的,我檢查了兩個json和xml版本 – Mahfuz

+0

我不認爲xml間距是問題。因爲我可以使用cURL發佈相同的XML。 –