显示来自youtube api c的详细信息#

时间:2017-01-03 10:46:20

标签: c# asp.net arrays api youtube

尝试从Youtube API显示播放列表详细信息,api成功运行并获取信息,但我不知道如何显示除console.writeLine之外收到的信息,我希望能够以.net站点和格式显示它已经获得了分配给变量的信息,但不知道如何将它们转换为可查看的对象

代码如下: API代码:

/*
*/
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using Google.Apis.Auth.OAuth2; 
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;


public class uploaded_videos
{
//adapted from youtube api code samples for .net
 public async Task Run(Video_details vidDetails)
    {
    //Google API validation
        UserCredential credential;
        using (var stream = new                FileStream(@"C:\Users\siobhan\Documents\Visual Studio 2015\WebSites\FYP_November\Client_id_googleApi.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                // This OAuth 2.0 access scope allows for read-only access to the authenticated 
                // user's account, but not other types of account access.
                new[] { YouTubeService.Scope.YoutubeReadonly },
                "user",
                CancellationToken.None,
                new FileDataStore(this.GetType().ToString())
            );
        }

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = this.GetType().ToString()
        });

        var channelsListRequest = youtubeService.Channels.List("contentDetails");
        channelsListRequest.Mine = true;

        // Retrieve the contentDetails part of the channel resource for the authenticated user's channel.
        var channelsListResponse = await channelsListRequest.ExecuteAsync();

        foreach (var channel in channelsListResponse.Items)
        {
            // From the API response, extract the playlist ID that identifies the list
            // of videos uploaded to the authenticated user's channel.
            var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;

            Console.WriteLine("Videos in list {0}", uploadsListId);

            var nextPageToken = "";
            while (nextPageToken != null)
            {
                var playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet");
                playlistItemsListRequest.PlaylistId = uploadsListId;
                playlistItemsListRequest.MaxResults = 50;
                playlistItemsListRequest.PageToken = nextPageToken;

                // Retrieve the list of videos uploaded to the authenticated user's channel.
                var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();

                foreach (var playlistItem in playlistItemsListResponse.Items)
                {
                // Print information about each video.

                //Console.WriteLine("{0} ({1})",playlistItem.Snippet.Thumbnails, playlistItem.Snippet.Title, playlistItem.Snippet.ResourceId.VideoId);
                playlistItem.Snippet.ResourceId.VideoId = vidDetails.vidId;
                playlistItem.Snippet.Title= vidDetails.vidTitle;
                //playlistItem.Snippet.Thumbnails.Standard = vidDetails.vidThumb;




                }

                nextPageToken = playlistItemsListResponse.NextPageToken;
            }
        }
    }
}

网站视图的ASP类:

public partial class ProfilePage : System.Web.UI.Page
{
protected async void Page_Load(object sender, EventArgs e) { 

    Video_details vidDetails = new Video_details();

    uploaded_videos uploadedVids = new uploaded_videos();
    await new uploaded_videos().Run(vidDetails);

    vidDetails.vidId = lblVideo3.Text;
    vidDetails.vidTitle = lblVideo2.Text;



    //vidDetails.vidThumb = imgVid1....



}
}

任何帮助都会很棒!

0 个答案:

没有答案