Youtube Data API v3 - Get video feeds of auto-generated channels

后端 未结 1 1195
臣服心动
臣服心动 2021-01-28 21:51

I want to use auto-generated channel Ids as example below...

GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UCrfjym-5AEUY2QzXsddRIQA&fields=i

相关标签:
1条回答
  • 2021-01-28 22:45

    FINAL UPDATE:

    Here is my solution for auto-generated Topic-based channel ids, since I'm using gapi.client, here's what works (relevant code only - URL samples below):

    function requestUserUploadsPlaylistId(pageToken) {
    var itemId = $("#YOUR-TEXT-INPUT").val(CHANNEL-ID); // Topic-based channel Id
    var request = gapi.client.youtube.playlists.list({ // Use playlists.list
    channelId: itemId, // Return the specified channel's playlist
    part: 'snippet',
    filter: 'items(id)' // This gets what you only need, the playlist Id
    });
    request.execute(function(response) {
    playlistId = response.result.items[0].id;
    requestVideoPlaylist(playlistId, pageToken); // Now call function to get videos
    });
    }
    
    function requestVideoPlaylist(playlistId, pageToken) {
    var requestOptions = {
    playlistId: playlistId,
    part: 'id,snippet',
    maxResults: 6
    };
    
    var request = gapi.client.youtube.playlistItems.list(requestOptions);
    request.execute(function(response) { // playlistItems.list is used here
    . . .
    

    Here's the URL sample of auto-generated Topic-based Id which grabs its playlist id: GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=HC9m3exs6zk1U&fields=items%2Fid&key={YOUR_API_KEY} // Outputs sample playlist Id: LP9m3exs6zk1U

    Now here's the URL sample using that playlist Id to get the videos from the auto-generated Topic-based channel Id: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=5&playlistId=LP9m3exs6zk1U&key={YOUR_API_KEY} // Outputs video data you want.

    Remember, Topic-based channel Ids come in different lengths, the above samples support current available lengths.

    Hope This Helps!

    0 讨论(0)
提交回复
热议问题