2015-05-17 31 views
0

https://developer.linkedin.com/documents/code-samplesLinkedIn代碼示例返回NULL用戶對象

使用上面的PHP代碼示例,我可以登錄到我的用戶的個人資料如預期,(創建所需的「應用程序」和獲得的API密鑰和密碼,之後當然。)

但是,由Fetch()函數返回的$ user對象爲null,所以我沒有通過代碼訪問配置文件內容,例如$ user-> firstname和$ user-> lastname等

供參考:此問題之前被問及未回答: LinkedIn Code Sample not returning ay data

回答

0

我發現的問題是,file_get_contents()不工作,這是因爲allow_url_fopen沒有在PHP.ini中啓用。我相信allow_url_fopen默認情況下沒有啓用,因爲它是一個安全問題。我在網上找到了使用cUrl的解決方法。請參閱下面的代碼。

//首先,在getAccessToken()替換 $響應的file_get_contents =($網址,假,$上下文) 與 $響應= curl_get_contents($網址);

將以下函數添加到代碼示例中。

function curl_get_contents($url) 
{ 
    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 

    $data = curl_exec($ch); 
    curl_close($ch); 

    return $data; 
}