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.
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.
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.
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