Youtube API v3 Universal Javascript Library for nodeJS, AMD and browser which provides easy API
No Jquery needed.
Example
var youtube = require('ytjs')("API KEY");
youtube.getdata({ videoId: "TlgqWeuhJj4"},function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
include yt.js
<script type="text/javascript" src="yt.js" ></script>
Initalize the library and get Data
var youtube = $youtube("API KEY");
youtube.getdata({ videoId: "TlgqWeuhJj4" },function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
youtube.getdata({ videoId: "PMr2NRPdpH4"}, function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
Methods Available
- getdata
- search
- getComments
- getRelatedVideos
youtube.getdata({ videoId: "TlgqWeuhJj4" },function(err, result){
if(err) {
console.log(err);
return false;
}
console.log(result);
});
youtube.search({keyword: "rihanna love", fullResults: 1, order: "relevance"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
youtube.getComments({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
youtube.getRelatedVideos({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
- videoId : youtube video id
- part: "snippet,statistics,contentDetails" // you can pass either of three orcombination or all
You can get wide variety of data from getdata
method and always youtube original data can be referred in raw
"title":
"description":
"rating":
"views":"",
"publishedAt":
"dthumbnail":
"mthumbnail":
"hthumbnail":
"sthumbnail":
"categoryId":
"channelTitle":
"videoId":"",
"duration":
"mins":
"hr":
"secs":
"dimension":
definition":
caption":
licensedContent":
"viewCount":
"likeCount":
"dislikeCount":
"favoriteCount":
"commentCount":
"kind":
"channelId":
"thumbnails":{}
"tags":{}
"liveBroadcastContent":"none"
"localized":{}
"projection":
"raw":{}
- keyword : keyword for search
- order: "relevance" // date, rating, viewCount, videoCount, title
- type : "basic" // "detailed" will provide additional information for each search video
- navigate : "next" // would render next set of results as youtube only allows 50 videos at a time
You can get wide variety of data from search
method. Results of search will be returned in videos
array and always youtube original data can be referred in raw
"videos" : []
nextPageToken:
prevPageToken:
kind:
youtube.getComments({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
nextComments();
});
// next set of comments
function nextComments() {
youtube.getComments({videoId: "PMr2NRPdpH4", navigate: "next"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
}
You can get wide variety of data from getComments
method. Results of comments will be returned in items
array and always youtube original data can be referred in raw
items
array item usually have different values such as textDisplay
, authorDisplayName
, authorProfileImageUrl
, likeCount
etc
items : []
nextPageToken:
prevPageToken:
resultsPerPage:
raw:
youtube.getRelatedVideos({videoId: "PMr2NRPdpH4"}, function(err, data){
if(err) {
console.log(err);
return false;
}
console.log(data);
});
You can get wide variety of data from getRelatedVideos
method. Results of related videos will be returned in videos
array and always youtube original data can be referred in raw
"videos" : []
nextPageToken:
prevPageToken:
kind:
Debug mode will print details to your console. you can enable debug mode during intialization by passing true
var youtube = $youtube("API KEY", true);
[ x ] get Video Data
[ x ] search for videos
[ x ] get Comments
[ x ] npm module
[ x ] related videos
[ ] Please open an issue