2016-09-23 28 views
0

我試圖從Instagram中提取用戶個人資料圖片,但我無法成功地成功地將echo所需的數組。如何從cURL JSON中正確提取數組?

$url="https://www.instagram.com/selenagomez/media/"; 

// Initiate curl 
$ch = curl_init(); 
// Disable SSL verification 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
// Set the url 
curl_setopt($ch, CURLOPT_URL,$url); 
// Execute 
$json=curl_exec($ch); 
// Closing 
curl_close($ch); 

$result = json_decode($json, true); 

echo $result[0]["profile-picture"]; 

我越來越:Notice: Undefined offset: 0 in test.php on line 23

還試圖排除第二JSON參數(true),它並沒有幫助。

回答

1

的JSON以上網址如下:

http://image.prntscr.com/image/2436f32c4e4045988e3fb0aa05cf1502.png

Source

所以,你需要你的抓地力適應這個:

$results['items'][0]['user']['profile_picture']; 

這將輸出

https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xfl1/t51.2885-19/s150x150/12918537_1719366751611008_1708400518_a.jpg 

返回上一級樹得到user財產及其所有子

$user = $results['items'][0]['user']; 
+0

太謝謝你了! – Ricardo