Displaying Youtube Videos From Specific Channel

前端 未结 2 414
暗喜
暗喜 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 = '<li>' + item.snippet.title + '</li>';
    				$('#results').append(results);
    			});
    		}
    	);
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="row-fluid">                
    	<ul id="results"></ul>
    
    	<input type="hidden" id="pageToken" value="" />
    	<div class="btn-group" role="group" aria-label="...">
    		<button type="button" id="pageTokenPrev" value="" class="btn btn-default">Prev</button>
    		<button type="button" id="pageTokenNext" value="" class="btn btn-default">Next</button>
    	</div>
    </div>

    0 讨论(0)
  • 2020-12-20 08:40

    After reading different Youtube apis i found following steps to consume Youtube Channel Videos in your Android app.

    1) Create an application in your Google Account 2) Enable youtube services 3) and then you will get developer key

    use that developer key to make api calls.

    4)

    String url = "https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=UCjD0Dhs3o7UiUQdZpSBADAA&key=" + DeveloperKey.DEVELOPER_KEY;
    

    Use cannel id in above URL along with developer key to get list of videos under your channel.

    5) You will get basic information of each video but still you cannot play that video in your android video player in order to do that you must have RTSP url

    and that url you can obtain by passing video id to http://gdata.youtube.com/feeds/mobile/videos/1FJHYqE0RDg

    That's all.

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