示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var clientId     = WebConfigurationManager.AppSettings["clientId"];
        var clientSecret = WebConfigurationManager.AppSettings["clientSecret"];
        var refreshToken = WebConfigurationManager.AppSettings["refreshToken"];

        var youTubeApiRestClient = new YouTubeApiRestClient.YouTubeApiRestClient(clientId, clientSecret, refreshToken);
        var video = new Video
        {
            Snippet = new VideoSnippet
            {
                Title       = "Default Video Title",
                Description = "Default Video Description",
                Tags        = new[] { "tag1", "tag2" },
                CategoryId  = "22" // See https://developers.google.com/youtube/v3/docs/videoCategories/list
            },
            Status = new VideoStatus
            {
                PrivacyStatus = "unlisted" // or "private" or "public"
            }
        };
        var filePath = @"REPLACE_ME.mp4"; // Replace with path to actual movie file.

        using (var fileStream = new FileStream(filePath, FileMode.Open))
        {
            video         = youTubeApiRestClient.UploadVideo(video, "snippet,status", fileStream, "video/*");
            litVideo.Text = string.Format("Video id '{0}' was successfully uploaded.", video.Id);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var clientId     = WebConfigurationManager.AppSettings["clientId"];
        var clientSecret = WebConfigurationManager.AppSettings["clientSecret"];
        var refreshToken = WebConfigurationManager.AppSettings["refreshToken"];

        var youTubeApiRestClient = new YouTubeApiRestClient.YouTubeApiRestClient(clientId, clientSecret, refreshToken);

        //Create a new, private playlist in the authorized user's channel.
        var newPlaylist = new Playlist
        {
            Snippet = new PlaylistSnippet
            {
                Title       = "Test Playlist",
                Description = "A playlist created with the YouTube API v3"
            },
            Status = new PlaylistStatus
            {
                PrivacyStatus = "public"
            }
        };

        newPlaylist = youTubeApiRestClient.InsertPlaylist(newPlaylist, "snippet,status");

        // Add a video to the newly created playlist.
        var newPlaylistItem = new PlaylistItem
        {
            Snippet = new PlaylistItemSnippet
            {
                PlaylistId = newPlaylist.Id,
                ResourceId = new ResourceId
                {
                    Kind    = "youtube#video",
                    VideoId = "GNRMeaz6QRI"
                }
            }
        };

        newPlaylistItem = youTubeApiRestClient.InsertPlaylistItem(newPlaylistItem, "snippet");

        litPlaylistItem.Text = string.Format("Playlist item id {0} was added to playlist id {1}.", newPlaylistItem.Id, newPlaylist.Id);
    }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var apiKey = WebConfigurationManager.AppSettings["apiKey"];

        var youTubeApiRestClient = new YouTubeApiRestClient.YouTubeApiRestClient(apiKey);

        string part       = "snippet";
        string q          = "Google";
        long?  maxResults = 50;
        var    response   = youTubeApiRestClient.Search(part, q, maxResults);

        List <string> videos    = new List <string>();
        List <string> channels  = new List <string>();
        List <string> playlists = new List <string>();

        // Add each result to the appropriate list, and then display the lists of
        // matching videos, channels, and playlists.
        foreach (var searchResult in response.Items)
        {
            switch (searchResult.Id.Kind)
            {
            case "youtube#video":
                videos.Add(string.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId));
                break;

            case "youtube#channel":
                channels.Add(string.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId));
                break;

            case "youtube#playlist":
                playlists.Add(string.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId));
                break;
            }
        }

        litVideos.Text    = string.Format("Videos:<br/>{0}<br/>", string.Join("<br/>", videos));
        litChannels.Text  = string.Format("Channels:<br/>{0}<br/>", string.Join("<br/>", channels));
        litPlayLists.Text = string.Format("Playlists:<br/>{0}<br/>", string.Join("<br/>", playlists));
    }