Get Total Number Of YouTube Views With PHP

Here’s a nice PHP snippet from Hal Gatewood that I’m sure YouTube account holders might be interested in. It’s a single line of PHP code that will get all of your YouTube uploaded video views (that’s right, just ONE!).

$youtube_view_count = json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/users/YOUR_CHANNEL?v=2&alt=json'))->entry->{'yt$statistics'}->totalUploadViews;

But if you prefer using a function, sure! Hal’s got one for you too.

function getYouTubeVideoViews($channel) {
 return json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/users/' . $channel . '?v=2&alt=json'))->entry->{'yt$statistics'}->totalUploadViews;
}
echo getYouTubeVideoViews('YOUR_CHANNEL');

Be sure to replace YOUR_CHANNEL with that of your own.

Hope you guys like this featured quick tip/tutorial of the day. Cheers!

Incoming search terms for the article:

Related Posts

How to Create a Clean and Elegant Blog Layout

Adding Expires Headers In Ruby On Rails

Validate Filename Before Uploading Image Using JavaScript

Logout Idle/Inactive Users Using PHP

1 Comment

  1. Hello there! This is my first comment here so I just wanted to give a quick shout out and say
    I really enjoy reading through your articles. Can you suggest any other blogs/websites/forums that cover the same subjects?
    Thank you so much!