How to use youtube v3.0 data API on meteor.js website?

I create a site using meteor.js

I reviewed related issues, but could not find a lot of useful information.

I am looking for meteor packing for the Youtube v3.0 Data API , which I can add as a package for my application. If there are no such shells, how can I use the API to search for videos by keywords?

I already knew the API documentation very well and I created an API key for my application. I cannot figure out how to authenticate my application using javaScript and search for videos.

Please let me know if I am missing information on the provision of information.

Appreciate your help. Many thanks.:)

+4
source share
1 answer

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:

// load future from fibers
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.

0
source

All Articles