在线为foreach()提供的参数无效

I am struggling to understand the error: "Invalid argument supplied for foreach() in on line" Basically it is a carousel showing images from instagram, but currently live is only showing the error msg.. If someone could assist, I would be grateful

<div class="gallery-carousel">
                <div id="insta-carousel" class="owl-carousel">  
                <?php
                    $instagram = new Instagram('I've taken my key out here, while public');
                    $data = $instagram->getUserMedia(973690696,10);
                    foreach($data->data as $media) :
                        if($media->type === 'image'):  

                ?>

                    <div><img class="insta-img" width="231px" height="231px" src="<?php echo $media->images->low_resolution->url; ?>"></div>
                <?php
                        endif;
                    endforeach;
                ?>

                </div>
            </div>

Use if condition to check

if($data->data):
  foreach($data->data as $media) :

  endforeach;
endif;

The error "Invalid argument supplied for foreach() in on line" is occurring because your $data object is empty and you are passing empty/null object in FOREACH loop to iterate through.

Check you $data object by dumping it using var_dump()/print_r().

Also for precaution use error/exception handling or wrap your loops lke below,

 if(isset($data) && !empty($data))