views:

179

answers:

3

The question is very simple. How to get number of video views with YouTube API?

alt text

The task is simple but I would like to use that query on large number of videos very often. Is there any way to call their Youtube API and get it? (something like facebook http://api.facebook.com/restserver.php?method=links.getStats&urls=developers.facebook.com)

+1  A: 

This probably is not what you want but you could scrap the page for the information using the following:

document.getElementsByClassName('watch-view-count')[0].innerHTML
Ryan Alberts
download the whole page and then do this? hm..
Ante B.
I agree - an API would be much more preferable...
Ryan Alberts
+2  A: 

I think, the easiest way, is to get video info in JSON format. If you want to use JavaScript, try jQuery.getJSON()... But I prefer PHP:

<?php
$video_ID = 'your-video-ID';
$JSON = file_get_contents("http://gdata.youtube.com/feeds/api/videos?q={$video_ID}&amp;alt=json");
$JSON_Data = json_decode($JSON);
$views = $JSON_Data->{'feed'}->{'entry'}[0]->{'yt$statistics'}->{'viewCount'};
echo $views;
?>
B7ackAnge7z
Thanks, you saved me 30 mins of digging around :)
Martin
+1  A: 

look at yt:statistics tag. It provides viewCount, videoWatchCount, favoriteCount etc.

Rajani Karuturi