Skip to content

Instantly share code, notes, and snippets.

@jonathan-nwosu
Created May 19, 2017 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathan-nwosu/2698ccca663b2d72f46552c19bdc4417 to your computer and use it in GitHub Desktop.
Save jonathan-nwosu/2698ccca663b2d72f46552c19bdc4417 to your computer and use it in GitHub Desktop.
<?php
$api_link = file_get_contents("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=5&q=glossybox&key=AIzaSyD2dr0l03UuGH9gU2z9OD8X5kLY5kizAwE");
$encode = json_decode($api_link);
for ($i=0; $i < 5; $i++) {
$results = $encode->items[$i]->id->videoId;
echo "<div class='video_wrap'><iframe class='videos' width='300' height='200'src='http://www.youtube.com/embed/$results'></iframe><br>";
$api_key = 'AIzaSyB7eYjYk2c6kbgKpxVZODWoSe1qZUAtSb4';
$youtube_data = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$results&key=$api_key");
$data = json_decode($youtube_data, true);
$youtube_data_snippet = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$results&key=$api_key");
$data_snippet = json_decode($youtube_data_snippet, true);
$results_snippet = $data_snippet['items'][0]['snippet'];
$date_snippet = $results_snippet['publishedAt'];
$channel_title = $results_snippet['channelTitle'];
$date = substr($date_snippet, 0, -14);
$views = $data['items'][0]['statistics']['viewCount'];
$likes = $data['items'][0]['statistics']['likeCount'];
$comments = $data['items'][0]['statistics']['commentCount'];
$dislikes = $data['items'][0]['statistics']['dislikeCount'];
//$query_second = ucfirst($user_text);
$views = number_format($views);
$likes = number_format($likes);
$comments = number_format($comments);
echo "<div class='video_content_text'><br>
Username: $channel_title<br><br>
Upload Date: $date<br><br>
Views: $views <br><br>
Likes: $likes <br><br>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment