0

Hey all wondering if i can use youtube api's to get the TOTAL number of youtube plays - wondering if they offer this statistic to public through their API's.

I want to get the live count to every few seconds.

Towelie
  • 92
  • 1
  • 14

2 Answers2

0

Take a look at Youtube API's web page. At a first glande I've seen this link.

In there you'll find metrics as mandatory parameter of the request. In such parameter you may specify which metrics you want to retrieve (for instance, views, likes, dislikes). Take also a look at the further descriptions of metrics in this link.

kazbeel
  • 1,378
  • 19
  • 40
0

Working jQuery Example: Get view count and video title (Created quickly by me)

Example Fiddle URL: http://jsfiddle.net/mu9wwmza/

Working Source: Below....

<input value="CplTXmbJj3g" type="text" id="txtVidID" />
<input type='button' onclick="getViewsFromYT()" value="Query Video Stats" />
<script>
    function getViewsFromYT() {
        var sURL = "https://gdata.youtube.com/feeds/api/videos/" + $("#txtVidID").val() + "?v=2&alt=json";
        $.getJSON( sURL, function( data ) {
            var sTitle = data.entry['media$group']['media$title']['$t'];
            var iCount = data.entry['yt$statistics'].viewCount;
            alert(iCount + " views for : " + sTitle);        

        });
    }
<script>

What does it do?? Well simply it will grab the contents of a URL like THIS and will then grab the name and view variables to alert them back to the user.

EDIT - PER CHANNEL something like this url:https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=ExplosmEntertainment&key={YOUR_API_KEY}

Will give you a response of something like this:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/wFb6RBgqjeO72V-0OhHhka5ADvI\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {

   "kind": "youtube#channel",
   "etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/iOZxog5cbjPLsV37DfO_fkODBDk\"",
   "id": "UCWXCrItCF6ZgXrdozUS-Idw",
   "statistics": {
    "viewCount": "594362694",
    "commentCount": "923",
    "subscriberCount": "3976887",
    "hiddenSubscriberCount": false,
    "videoCount": "121"
   }
  }
 ]
}

You can test this with their v3 API https://developers.google.com/youtube/v3/docs/channels/list#try-it


A quick google returned this as the first result: https://developers.google.com/youtube/2.0/developers_guide_protocol_insight

In the section Insight reports and their contents it shows the Views which can be specified to a time frame, so you would simply apply this from the date you uploaded the video to the current date/time.

Second google result was: How to get number of video views with YouTube API?

<?php
  $video_ID = 'your-video-ID';
  $JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos/{$video_ID}?v=2&alt=json");
  $JSON_Data = json_decode($JSON);
  $views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'viewCount'};
  echo $views;
?>

And this link Retrieve public statistics of video via youtube api refers to v3, but i would need to setup a video to test it further... Should give you a starting point

Community
  • 1
  • 1
Angry 84
  • 2,935
  • 1
  • 25
  • 24
  • Hey there - this is for a single youtube video - i'm looking for all the views from all videos posted on youtube. I've searched through the api's & I understand that I can get total views from an entire channel. – Towelie Apr 02 '15 at 07:47
  • In that case you want something like this: https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=ExplosmEntertainment&key={YOUR_API_KEY} but just noting you did not mention in your question relating to a channel.. So the assumption in this case is per video. – Angry 84 Apr 03 '15 at 00:23