Skip to content

Instantly share code, notes, and snippets.

@gabrielchavezme
Created August 11, 2018 02:51
Show Gist options
  • Save gabrielchavezme/5c58d63101e3512dd4a8cf6b048b9610 to your computer and use it in GitHub Desktop.
Save gabrielchavezme/5c58d63101e3512dd4a8cf6b048b9610 to your computer and use it in GitHub Desktop.
YouTube Sync with PHP API
<?php
$key = "TU_KEY_DE_GOOGLE_CONSOLE";
$canal = "ID_DEL_CANAL";
$max = 'CANTIDAD MAXIMA DE RESULTADOS';
$videos = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$canal.'&maxResults='.$max.'&key='.$key.''));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<?php
foreach ($videos->items as $video) {
if(isset($video->id->videoId)){
echo '
<div class="col-md-4">
<iframe width="100%" height="500" src="https://www.youtube.com/embed/'.$video->id->videoId.'" frameborder="0" allowfullscreen></iframe>
<h2>'.$video->videoTitle.'</h2>
</div>';
}
}
?>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment