public async Task Run(MediaFile.MediaFile mediaFile, string tittle, string description) { UserCredential credential; using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, //This OAuth 2.0 access scope allows for full read/ write access to the //authenticated user's account. new[] { YouTubeService.Scope.Youtube }, "user", CancellationToken.None, new FileDataStore(this.GetType().ToString()) ); } var youtubeService = new YouTubeService(new BaseClientService.Initializer() { // ApiKey = "AIzaSyDntWkrZCMiOFMef733L2aAxtzv4bImrPs", HttpClientInitializer = credential, ApplicationName = Assembly.GetExecutingAssembly().GetName().Name }); var video = new Video(); video.Snippet = new VideoSnippet(); video.Snippet.Title = tittle; video.Snippet.Description = description; video.Snippet.Tags = new string[] { "tag1", "tag2" }; video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list video.Status = new VideoStatus(); video.Status.PrivacyStatus = "public"; // or "private" or "public" var filePath = mediaFile._filePath; if (mediaFile._openFileDialog.FilterIndex == 5) { using (var fileStream = new FileStream(filePath, FileMode.Open)) { var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*"); videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged; const int KB = 0x400; var minimumChunkSize = 256 * KB; videosInsertRequest.ChunkSize = minimumChunkSize * 1; videosInsertRequest.Upload(); } } else { MessageBox.Show("błędny format pliku"); } }
public static void Publish(MediaFile.MediaFile mediaFile, string tittle, string description) { try { new YouTubeAP().Run(mediaFile, tittle, description).Wait(); } catch (AggregateException ex) { foreach (var e in ex.InnerExceptions) { MessageBox.Show("Error: " + e.Message); } } }
public static void Publish(string text, MediaFile.MediaFile mediaFile) { if (Accessik != null) { facebookClient = new FacebookClient(Accessik); if (text != null && mediaFile == null) { facebookClient.Post("/me/feed", new { message = text }); MessageBox.Show("Opublikowano status!"); } else { if (text != null && mediaFile._openFileDialog.FilterIndex == 5) { FacebookMediaObject facebookMediaObject = new FacebookMediaObject { FileName = mediaFile._openFileDialog.FileName, ContentType = "video/mp4" }; facebookMediaObject.SetValue(mediaFile._fileBytes); var postInfo = new Dictionary <string, object>(); postInfo.Add("message", text); postInfo.Add("image", facebookMediaObject); facebookClient.Post("/" + "117306115306848" + "/videos", postInfo); MessageBox.Show("Opublikowano status z plikiem video"); } else if (text != null) { FacebookMediaObject facebookMediaObject = new FacebookMediaObject { FileName = mediaFile._openFileDialog.FileName, ContentType = "image/jpg" }; facebookMediaObject.SetValue(mediaFile._fileBytes); var postInfo = new Dictionary <string, object>(); postInfo.Add("message", text); postInfo.Add("image", facebookMediaObject); facebookClient.Post("/" + "117306115306848" + "/photos", postInfo); MessageBox.Show("Opublikowano status z obrazkiem"); } } } else { MessageBox.Show("Zaloguj się"); } }
public static async void Publish(string text, MediaFile.MediaFile mediaFile) { if (text != null && mediaFile == null) { _loggedUser.PublishTweet(text); await MetroWindow.ShowMessageAsync("TWITTER TIMELINE", "Opublikowano tweeta!"); } else { if (text != null && mediaFile._openFileDialog.FilterIndex == 5) { Tweet.TweetController.PublishTweetWithVideo(text, mediaFile._fileBytes); await MetroWindow.ShowMessageAsync("TWITTER TIMELINE", "Opublikowano tweeta z plikiem video!"); } else if (text != null) { Tweet.PublishTweetWithImage(text, mediaFile._fileBytes); await MetroWindow.ShowMessageAsync("TWITTER TIMELINE", "Opublikowano tweeta z obrazkiem!"); } } }
public void AddFile() { _mediaFile = new MediaFile.MediaFile(); _mediaFile.AddFile(); }