Jump to content

Am Getting this foreach () Error In My Youtube Grabber [Please Help]


Stancobridge
 Share

Recommended Posts

Hello everyone!

 

Am having problem with the youtube grabber I uploaded in my site. The first time I uploaded it on my host it worked well but later stopped. All I see is

 

Warning: Invalid argument supplied for foreach() in.... on line 13

 

but later it disappeared and started working well yesterday night the grabber didn't work at all, when am about to make this post I wish to post the screenshort but going to my site to screenshort it I found out that the grabber has started working normal again. Am tired of all this partial contact in the please because I know that very soon it will stop again.

 

Here is the php script of homepage that it do occur

<?php
    include "conf.php";
    include "header.php";
    $fetchURI="https://www.googleapis.com/youtube/v3/search?type=video&q=bollywood&key=$api_key∂=snippet&maxResults=24";
    $ch=curl_init($fetchURI);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $data=curl_exec($ch);
    curl_close($ch);
    $datas=json_decode($data);
    $sdata="";
    $fetch_data=$datas->items;
    foreach($fetch_data as $vid){
        $vidId=$vid->id->videoId;
        $thumb_uri=$vid->snippet->thumbnails->medium->url;
        $title=$vid->snippet->title;
        $time=strtotime($vid->snippet->publishedAt);
        $date=date("jS, F Y", $time);
        $sdata.='
                <div class="v-item">
                    <div class="pplay">
                        <a href="'.$base.'/view/'.$vidId.'.html"><span class="fa fa-play"></span></a>
                    </div>
                    <img src="'.$thumb_uri.'">
                    <a href="'.$base.'/view/'.$vidId.'.html">'.$title.'</a>
                    <div class="time-in"><span class="fa fa-clock-o"></span> '.$date.'</div>
                </div>';
    }
?>
    <div class="w3-row v-cont" id="fsts">
        <div class="w3-row w3-padding w3-margin">
            <div class="w3-left">
                <h1>Newest Videos</h1>
            </div>
        </div>
        <?=$sdata?>
    </div>
<?php include "footer.php"; ?>
Edited by Stancobridge
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...