tessguefen
5/11/2015 - 1:58 PM

Youtube API

Youtube API

<?php
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_URL,"https://www.googleapis.com/youtube/v3/search?key=SECRETKEY&channelId=CHANNELID&part=snippet,id&order=date&maxResults=5");
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	$result = curl_exec($ch);
	curl_close($ch);

	$jsondata = json_decode($result,true);
	$videos = $jsondata['items'];

	echo '<div class="row">';
		foreach($videos as $video){
			$title = str_replace('www.lotussculpture.com', '', $video['snippet']['title']);
			echo '<div class="column whole youtube-video align-center" data-id="'.$video['id']['videoId'].'">';
				echo '<span class="yt-community-title"><a href="https://www.youtube.com/watch?v='.$video['id']['videoId'].'" target="_blank">'.$title.'</a></span>';
				echo '<img src="'. $video['snippet']['thumbnails']['medium']['url'].'" />';
				echo '<div class="video-hold"></div>';
			echo '</div>';
		}
	echo '</div>';
?>