簡體   English   中英

注意:試圖獲取非對象的屬性以打印instagram照片

[英]Notice: Trying to get property of non-object to print instagram photos

我正在嘗試打印instagram照片,但出現錯誤:

注意:試圖在...中獲取非對象的屬性

警告:為...中的foreach()提供了無效的參數

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>';
     }
}

我認為這是PHP版本問題。 在線上傳后,沒有任何錯誤。 在本地主機上,它顯示錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM