azmicolejr

Youtube API

Apr 16th, 2018
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2.         $API_key    = 'XXXX';
  3.         $channel_id  = 'XXXX';
  4.         $limit = 6;
  5.  
  6.         $videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?key='.$API_key.'&channelId='.$channel_id.'&part=snippet,id&order=date&maxResults='.$limit.''));
  7.         foreach($videoList->items as $item)
  8.         {
  9.           //Embed video
  10.           if(isset($item->id->videoId))
  11.           {
  12.             echo '<div class="col-lg-6">
  13.                    <iframe width="300" height="150" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe><br>
  14.                  </div>';
  15.           }
  16.         }
  17.         ?>
Advertisement
Add Comment
Please, Sign In to add comment