You can use the renaldo package: youtube-api .
To search for youtube, create the following server method
YoutubeApi.authenticate({
type: 'key',
key: 'Your-API-Key'
});
Meteor.methods({
searchVideo: function(search) {
YoutubeApi.search.list({
part: "id",
type: "video",
maxResults: 5,
q: search,
}, function (err, data) {
console.log(err, data);
});
}
});
If you want to return data back to the client, use Futures. For example, retrieving data associated with a video by ID.
Add this package (may work without it):
meteor add meteorhacks:npm
and server side:
var Future = Meteor.npmRequire("fibers/future");
Meteor.methods({
this.unblock();
var future = new Future();
getByVideoId: function(id) {
YoutubeApi.videos.list({
part: ["snippet", "contentDetails"],
type: "video",
maxResults: 1,
id: id,
}, function (err, data) {
console.log(err, data);
future.return({item:data});
});
return future.wait();
}
});
In addition, the official Youtube documentation is a very useful resource.
source
share