2016-10-16 5 views
0

Instagramの印刷する非オブジェクトのプロパティを取得しようとすると:お知らせ:私は私のInstagramの写真を印刷しようとしていますが、エラーがある写真

Notice: Trying to get property of non-object in...

Warning: Invalid argument supplied for foreach() in...

function fetchData($url){ 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
$result = curl_exec($ch); 
curl_close($ch); 
return $result; 
} 

$result = fetchData("https://api.instagram.com/v1/users/USERID/media/recent/?access_token=TOKEN"); 

$result = json_decode($result); 

foreach ($result->data as $post) { 
    if(empty($post->caption->text)) { 
     // Do Nothing 
    } 
    else { 
      echo '<a class="instagram-unit" target="blank" href="'.$post->link.'"> 
      <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="100%" height="auto" /> 
      <div class="instagram-desc">'.htmlentities($post->caption->text).' | '.htmlentities(date("F j, Y, g:i a", $post->caption->created_time)).'</div></a>'; 
    } 
} 
+1

'$ post'をチェックインする必要があります。オブジェクトではないプロパティにアクセスしている可能性があります。 '$ result'もチェックしてください。 –

答えて

0

私は、これはPHPのバージョンの問題だと思います。オンラインでアップロードした後、エラーはありません。 localhost上で、エラーを表示しています。

関連する問題