Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube API channel's videos list

I'm currently trying to make a site which uploads all the videos from specific playlist of some channel. Like list of videos. And I found this video - link. And that's what I have now:

$(document).ready(function() {
  $.get(
    "https://www.googleapis.com/youtube/v3/channels",{
      part : 'contentDetails', 
      forUsername : 'CHANNEL_NAME',
      key: 'MY_KEY'},
      function(data) {
        $.each( data.items, function( i, item ) {
          console.log(item);
        })
      }
  );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

But I have nothing in console, though judging by console.log(item) something must be there, at least undefined. And even when I write just console.log('hi') I still have nothing. I just can't understand what's wrong. Anyway, I'd be very thankful for any help.

like image 236
here4onequestion Avatar asked Jan 01 '18 19:01

here4onequestion


People also ask

How do I get a list of my YouTube channels?

It's at the top of the screen. This expands the search bar. Type the channel name into the "Search YouTube" bar. If you don't know the name of the channel, you can search for any keyword(s) that might bring it up in a search, such as the name of a video shared by the channel, a genre, etc.

What data can you get from YouTube API?

You can retrieve entire playlists, users' uploads, and even search results using the YouTube API. You can also add YouTube functionalities to your website so that users can upload videos and manage channel subscriptions straight from your website or app.


1 Answers

If I understood your question correctly, you want to retrieve videos of a specific channel. You should use https://www.googleapis.com/youtube/v3/search endpoint instead of https://www.googleapis.com/youtube/v3/channels. So, I provided an example with channelId and type parameters; (type parameter can be video, playlist, channel)

$(document).ready(function() {
  $.get(
    "https://www.googleapis.com/youtube/v3/search",{
      part : 'snippet', 
      channelId : 'UCR5wZcXtOUka8jTA57flzMg',
      type : 'video',
      key: 'MyKey'},
      function(data) {
        $.each( data.items, function( i, item ) {
          console.log(item);
        })
      }
  );
});

This will get you videos of a channel. If you want to get playlists of channel just change type parameter to playlist. Here is the official documentation.

like image 146
lucky Avatar answered Sep 25 '22 02:09

lucky