public void up() { string apiKey = @"AIzaSyCX0As8mlZ18e4aqIyproKLXzvVfBs5g84"; string clientId = @"222252918947-iid9u363jgp10b22m8ue8rg94n99roia.apps.googleusercontent.com"; string clientSecret = @"r910yCk1gF6Kedn0HG-hy6sT"; string refreshToken = @"1/UiEcrF6G_Aa7pLTNOImKexg1hJHUou_nFLf_sxi9W6oXh4EiMLan8fkpCLvFYxLj"; var youTubeApiRestClient = new YouTubeApiRestClient.YouTubeApiRestClient(apiKey); //var youTubeApiRestClient = new YouTubeApiRestClient.YouTubeApiRestClient( // clientId: clientId, // clientSecret: clientSecret, // refreshToken: refreshToken //); youTubeApiRestClient = new YouTubeApiRestClient.YouTubeApiRestClient(clientId, clientSecret, refreshToken); var video = new Video { Snippet = new VideoSnippet { Title = "最好的戒烟方式", Description = "最好的戒烟方式", Tags = new[] { "戒烟" }, CategoryId = "22" //CategoryId = "PL-S1JcRDBHbTT2GuGy8ehjiaQggFhTRg4" // See https://developers.google.com/youtube/v3/docs/videoCategories/list }, Status = new VideoStatus { PrivacyStatus = "public" // or "private" or "public" } }; var filePath = string.Empty; filePath = @"C:\Users\admin\Desktop\a1\01.mp4"; //filePath = AppDomain.CurrentDomain.BaseDirectory + "01.mp4"; using (var fileStream = new FileStream(filePath, FileMode.Open)) { try { video = youTubeApiRestClient.UploadVideo(video, "snippet,status", fileStream, "video/*"); Console.WriteLine(string.Format("Video id '{0}' was successfully uploaded.", video.Id)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
public List <YouTube> Search(string searchTerm, int maxResults) { var apiKey = WebConfigurationManager.AppSettings["YouTubeAPIKey"]; var youTubeApiRestClient = new YouTubeApiRestClient.YouTubeApiRestClient(apiKey); var result = youTubeApiRestClient.Search(part, searchTerm, maxResults); var youtube = new List <YouTube>(); foreach (var item in result.Items) { youtube.Add(new YouTube() { Description = item.Snippet.Description, Title = item.Snippet.Title, URL = $"https://www.youtube.com/embed/{item.Id.VideoId}" }); } return(youtube); }