Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to show the view count of my Youtube videos in my widget. I fetch Youtube feed by using the built-in Wordpress function fetch_feed. Everything worked OK but I got a problem when tried to get the view count of videos.

Could anyone tell me how can I get Youtube viewCount by using fetch_feed?

share|improve this question
This is a Youtube API Question. It should be moved to StackOverflow as they are now considered the "Official" Youtube API support forums. – Chris_O Sep 24 '12 at 6:22

closed as off topic by Chris_O, Brian Fegter, Otto, Bainternet Sep 24 '12 at 10:50

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

The Short answer is:

// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount']; 

A long example using a page i built to retrieve the data
of a playlist can be found here: http://pastebin.com/9xxcwL13

The code in the pastebin is a response to a form so you might
need to taylor it to your needs...

Hope this helps
Sagive.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.