Skip to content

How To Display YouTube Video Views Count In PHP

If you’re running a website where you embed/link YouTube videos then you might wanna display YouTube video views count on your website. Here’s how to do it. This snippet was used by me when I was working on a client’s website earlier this hour. This is probably the easiest way to display views count.

Just drop the following snippet:

Just drop the video ID in the first line in the above snippet.

If you wanna get video views by YouTube video URL, then you can use this snippet which will first get the video ID from the long URL to display views count:

Hope this snippet will help you out :)

3 thoughts on “How To Display YouTube Video Views Count In PHP”

  1. i used your code on my site that is running on localhost but count view not working.. i rechived that error

    Warning: file_get_contents(http://gdata.youtube.com/feeds/api/videos/EQFCT8YaYcE?v=2&alt=json): failed to open stream: HTTP request failed! HTTP/1.0 410 Gone in D:\xampp\htdocs\naseem\youtube\count.php on line 3

    Notice: Trying to get property of non-object in D:\xampp\htdocs\naseem\youtube\count.php on line 3

    Notice: Trying to get property of non-object in D:\xampp\htdocs\naseem\youtube\count.php on line 3

    Notice: Trying to get property of non-object in D:\xampp\htdocs\naseem\youtube\count.php on line 3

Leave a Reply

Your email address will not be published. Required fields are marked *