Youtube api v3 Get list of user's videos

2019-01-08 03:28发布

With Youtube api v2, there's easy way to get videos. Just send a query like this:

http://gdata.youtube.com/feeds/mobile/videos?max-results=5&alt=rss&orderby=published&author=OneDirectionVEVO

The Youtube api v2 also has an interactive demo page for building query: http://gdata.youtube.com/demo/index.html

With Youtube api v3, I don't know the corresponding way. Please point me the way with api v3.

Thank you!

13条回答
【Aperson】
2楼-- · 2019-01-08 04:06
$.get(
    "https://www.googleapis.com/youtube/v3/channels",{
      part: 'snippet,contentDetails,statistics,brandingSettings',
      id: viewid,
      key: api},
      function(data){

        $.each(data.items, function(i, item){


          channelId = item.id;
          pvideo = item.contentDetails.relatedPlaylists.uploads;
          uploads(pvideo);
});

      });

Uploads Function can be

function uploads(pvideo){


       $.get(
        "https://www.googleapis.com/youtube/v3/playlistItems",{
          part: 'snippet',
          maxResults:12,
          playlistId:pvideo,
          key: api},
          function(data){


            $.each(data.items, function(i, item){

                 videoTitle = item.snippet.title;
             videoId = item.id;
            description = item.snippet.description;
            thumb = item.snippet.thumbnails.high.url;
            channelTitle = item.snippet.channelTitle;
            videoDate = item.snippet.publishedAt;
            Catagoryid = item.snippet.categoryId;
            cID = item.snippet.channelId;

            })
          }
        );
     }
查看更多
做个烂人
3楼-- · 2019-01-08 04:07

In node.js, it can be achieved with following code.

Requires authKey and channelId as options object parameter.

cb callback is called after data is fetched.

async function fetchChannelInfo(options) {
  const channelUrl = `https://www.googleapis.com/youtube/v3/channels?part=contentDetails,statistics&id=${
    options.channelId
  }&key=${options.authKey}`;
  const channelData = await axios.get(channelUrl);

  return channelData.data.items[0];
}
function fetch(options, cb) {
  fetchChannelInfo(options).then((channelData) => {
    options.playlistId = channelData.contentDetails.relatedPlaylists.uploads;
    const paylistUrl = `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=${
      options.playlistId
    }&key=${options.authKey}`;

    axios
      .get(paylistUrl)
      .then((response) => {
        const payloadData = ;

        const videoList = [];
        response.data.items.forEach((video) => {
          videoList.push({
            publishedAt: video.snippet.publishedAt,
            title: video.snippet.title,
            thumbnails: thumbnails,
            videoId: video.snippet.resourceId.videoId,
          });
        });

        cb(null, videoList);
      })
      .catch((err) => {
        cb(err, null);
      });
  });
}

Note: axios is used for RESTful requests. To install

npm install axios
查看更多
爷的心禁止访问
4楼-- · 2019-01-08 04:09

function tplawesome(e,t){res=e;for(var n=0;n<t.length;n++){res=res.replace(/\{\{(.*?)\}\}/g,function(e,r){return t[n][r]})}return res}



$(function() {


    $(".form-control").click(function(e) {


       e.preventDefault();


       // prepare the request


       var request = gapi.client.youtube.search.list({


            part: "snippet",


            type: "video",


            q: encodeURIComponent($("#search").val()).replace(/%20/g, "+"),


            maxResults: 20,


            order: "viewCount",


            publishedAfter: "2017-01-01T00:00:00Z"


       }); 


       // execute the request


       request.execute(function(response) {


          var results = response.result;


          $("#results").html("");


          $.each(results.items, function(index, item) {


            $.get("tpl/item.html", function(data) {


                $("#results").append(tplawesome(data, [{"title":item.snippet.title, "videoid":item.id.videoId ,"descrip":item.snippet.description ,"date":item.snippet.publishedAt ,"channel":item.snippet.channelTitle ,"kind":item.id.kind ,"lan":item.id.etag}]));


            });


            


          });


          resetVideoHeight();


       });


    });


    


    $(window).on("resize", resetVideoHeight);


});



function resetVideoHeight() {


    $(".video").css("height", $("#results").width() * 9/16);


}



function init() {


    gapi.client.setApiKey("YOUR API KEY .... USE YOUR KEY");


    gapi.client.load("youtube", "v3", function() {


        // yt api is ready


    });


}

Check the Complete code here https://thecodingshow.blogspot.com/2018/12/youtube-search-api-website.html

查看更多
太酷不给撩
5楼-- · 2019-01-08 04:10

An alternative method may be to get the playlists for the currently oauth authenticated user via: property mine=true

where the oauth access_token is retrieved following authentification: https://developers.google.com/youtube/v3/guides/authentication

https://www.googleapis.com/youtube/v3/playlists?part=id&mine=true&access_token=ya29.0gC7xyzxyzxyz
查看更多
小情绪 Triste *
6楼-- · 2019-01-08 04:11

In case it helps anyone here this is what I discovered and so far seems to be working well for me. I am authenticating the member via OAuth 2.0 prior to making this request, which will give me the authenticated members videos. As always, your personal mileage may vary :D

curl https://www.googleapis.com/youtube/v3/search -G \
-d part=snippet \
-d forMine=true \
-d type=video \
-d order=date \
-d access_token={AUTHENTICATED_ACCESS_TOKEN}
查看更多
太酷不给撩
7楼-- · 2019-01-08 04:12

Things have changed alot in V3 of the API. Here is a video that walks you through the v3 API calls needed to get a list of the videos uploaded in a given channel, with live demos using the API Explorer.

YouTube Developers Live: Getting a Channel's Uploads in v3 - https://www.youtube.com/watch?v=RjUlmco7v2M

查看更多
登录 后发表回答