Displaying Youtube Videos From Specific Channel

前端 未结 2 446
暗喜
暗喜 2020-12-20 08:14

I have created a youtube channel and uploaded few videos there. Channel is public, now i want to display those all uploaded videos in my android app through channel URL whic

2条回答
  •  执念已碎
    2020-12-20 08:26

    It is working fine for me. You can refer this answer for showing youtube channel videos into the website:

    $(document).ready(function () {
    	youtubeApiCall();
    
    	$("#pageTokenNext").on("click", function (event) {
    		event.stopImmediatePropagation();
    		$("#pageToken").val($("#pageTokenNext").val());
    		youtubeApiCall();
    	});
    
    	$("#pageTokenPrev").on("click", function (event) {
    		event.stopImmediatePropagation();
    		$("#pageToken").val($("#pageTokenPrev").val());
    		youtubeApiCall();
    	});
    });
    
    // Get Uploads Playlist
    function youtubeApiCall() {
    	$.get(
    		"https://www.googleapis.com/youtube/v3/channels", {
    			part: 'contentDetails',
                forUsername: 'bharatpillai007',
    			//id: {YOUTUBE CHANNEL ID}, //or you can call forUsername: {USER NAME} parameter of the your youtube channel
    			key: 'AIzaSyCKCyYrVLEKR7VR4BFlrC5AhhzYQGRIet4'
    		}, function (data) {
    
    			$.each(data.items, function (i, item) {
    				pid = item.contentDetails.relatedPlaylists.uploads;
    				getVids(pid);
    			});
    		}
    	);
    }
    
    //Get Videos
    function getVids(pid) {
    	$.get(
    		"https://www.googleapis.com/youtube/v3/playlistItems", {
    			part: 'snippet',
    			maxResults: 10, // Defualt 5. You can set 1 to 50
    			playlistId: pid,
    			key: 'AIzaSyCKCyYrVLEKR7VR4BFlrC5AhhzYQGRIet4',
    			pageToken: $("#pageToken").val()
    		}, function (data) {
    			var results;
    			$.each(data.items, function (i, item) {
    				if (typeof data.prevPageToken === "undefined") {
    					$("#pageTokenPrev").hide();
    				} else {
    					$("#pageTokenPrev").show();
    				}
    				if (typeof data.nextPageToken === "undefined") {
    					$("#pageTokenNext").hide();
    				} else {
    					$("#pageTokenNext").show();
    				}
    				
    				$("#pageTokenNext").val(data.nextPageToken);
    				$("#pageTokenPrev").val(data.prevPageToken);
    
    				results = '
  • ' + item.snippet.title + '
  • '; $('#results').append(results); }); } ); }
    
    

    提交回复
    热议问题