2016-09-23 19 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

上記URLの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プロパティを取得するには、ツリーの1つの上のレベル

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

ありがとうございました! – Ricardo

関連する問題