Displaying Youtube Videos From Specific Channel

2019-01-28 23:25发布

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 which is: https://www.youtube.com/channel/UCjD0Dhs3o7UiUQdZpSBADAA

I have also done some research but i am getting tutorial to display videos by hardcoded ids not from channel for example: https://github.com/youtube/yt-android-player

Any one guide me is it possible? i would really appreciate your help in matter.

Thank You!

2条回答
做个烂人
2楼-- · 2019-01-28 23:57

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.

查看更多
趁早两清
3楼-- · 2019-01-29 00:00

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>

查看更多
登录 后发表回答