Created
August 11, 2018 02:51
-
-
Save gabrielchavezme/5c58d63101e3512dd4a8cf6b048b9610 to your computer and use it in GitHub Desktop.
YouTube Sync with PHP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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