2
Answers

Search List of  Video

Ramco Ramco

Ramco Ramco

1w
43
1

Hi

  I have below code and i want to get Search List of  Video also

protected void MyOwnVideos11()
{
    StringBuilder htmlTable = new StringBuilder();
    string nextPageToken = string.Empty;
    Int32 Sr = 1;
    var client = new RestClient("googleapis.com/youtube/v3");
    var request = new RestRequest("search", Method.GET);
    request.AddParameter("type", "video");
    request.AddParameter("channelId", "UC_nNoaVw);
    request.AddParameter("key", "AIz8...");
    if (!string.IsNullOrEmpty(nextPageToken))
    {
        request.AddParameter("pageToken", nextPageToken);
    }
    var response = client.Execute<YoutubeSearchListResponse>(request);
    var orderByPublishAt = response.Data.items.OrderBy(x => x.snippet.publishedAt);
    htmlTable.Append("<table class='table table-bordered table-hover datatable-highlight' id='tbldata'>");
    htmlTable.Append("<thead><tr><th>Sr.</th><th>Video Title</th><th>Description</th<th>Published</th></tr></thead>");
    htmlTable.Append("<tbody>");
    do
    {
        foreach (var data in orderByPublishAt)
        {
            var clientTag = new RestClient("googleapis.com/youtube/v3/");
            var tagRequest = new RestRequest("videos", Method.GET);
            tagRequest.AddParameter("key", "AIz8...");
            tagRequest.AddParameter("part", "snippet,statistics");
            tagRequest.AddParameter("id", data.id.videoId);
            var tagResponse = clientTag.Execute<VideoListResponse>(tagRequest);
            foreach (var item in tagResponse.Data.items)
            {
                htmlTable.Append("<td >" + Sr + "</td>");
                htmlTable.Append("<td >" + item.snippet.title + "</td>");
                htmlTable.Append("<td >" + item.snippet.description + "</td>");
                htmlTable.Append("<td >" + data.snippet.publishedAt.ToString("dd-MM-yyyy") + "</td>");
                htmlTable.Append("</tr>");
            }
            Sr = Sr + 1;
            nextPageToken = response.Data.nextPageToken;
        }
    } while (!string.IsNullOrEmpty(nextPageToken));
    htmlTable.Append("</tbody>");
    htmlTable.Append("</table>");
    PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
}

Thanks

Answers (2)