/// <summary> /// Processing when OK button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OKButton_Click(object sender, RoutedEventArgs e) { try { // Issue ClientID and ClientSecrert of the instance Authorize authorize = new Authorize(); authorize.CreateApp(TextBox.Text, "DANMAKU via Mastodon", Scope.Read).Wait(); // Set settings Default.Instance = TextBox.Text; Default.ClientId = authorize.ClientId; Default.ClientSecret = authorize.ClientSecret; Default.AccessToken = null; // Open authentication url Process.Start(authorize.GetAuthorizeUri()); } catch { Default.Instance = null; Default.ClientId = null; Default.ClientSecret = null; } // Save settings Default.Save(); // Set DialogResult true and close window DialogResult = true; Close(); }
/// <summary> /// mastodon認証ボタン /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnOpenAuthorizeWindow_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMastodonInstanceDomain.Text.Trim())) { return; } _Authorize = new Authorize() { ClientId = Properties.Settings.Default.Mastodon_ClientKey , ClientSecret = Properties.Settings.Default.Mastodon_ClientSecret }; try { await _Authorize.CreateApp(txtMastodonInstanceDomain.Text.Trim(), Properties.Settings.Default.AppName, Scope.Write); System.Diagnostics.Process.Start(_Authorize.GetAuthorizeUri()); panel1.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Name, MessageBoxButtons.OK); } }
public async Task AuthorizeWithCodeTest() { var authorize = new Authorize { Instance = AccountInformation.Instance, ClientId = AccountInformation.ClientId, ClientSecret = AccountInformation.ClientSecret }; var authorizeUrl = authorize.GetAuthorizeUri(); Console.WriteLine(authorizeUrl); var code = Console.ReadLine()?.Trim(); var tokens = await authorize.AuthorizeWithCode(code); Assert.NotNull(tokens); Assert.NotNull(tokens.AccessToken); }
static async Task MainAsync() { var authorize = new Authorize(); await authorize.CreateApp("mstdn.jp", "Tootnet", Scope.Read | Scope.Write | Scope.Follow); var authorizeUrl = authorize.GetAuthorizeUri(); Console.WriteLine(authorizeUrl); Console.Write("code: "); var code = Console.ReadLine().Trim(); var tokens = await authorize.AuthorizeWithCode(code); Console.WriteLine(" -- List of commands -- "); Console.WriteLine("toot [status]"); Console.WriteLine("notification"); Console.WriteLine("home"); Console.WriteLine("ftl"); Console.WriteLine("ltl"); Console.WriteLine("help"); Console.WriteLine("quit"); Console.WriteLine("exit"); while (true) { Console.Write("command: "); var command = Console.ReadLine().Trim().Split(' ', 2); switch (command.First().ToLower()) { case "help": Console.WriteLine(" -- List of commands -- "); Console.WriteLine("toot [status]"); Console.WriteLine("notification"); Console.WriteLine("home"); Console.WriteLine("ftl"); Console.WriteLine("ltl"); Console.WriteLine("help"); Console.WriteLine("quit"); Console.WriteLine("exit"); break; case "quit": case "exit": return; case "toot": if (command.Length <= 1) { break; } var text = command[1].Trim(); var post = await tokens.Statuses.PostAsync(status => text); Console.WriteLine("--------------------"); Console.WriteLine(post.Account.DisplayName + "\t\t" + post.Account.Acct); Console.WriteLine(TagRegex.Replace(post.Content.Replace("<br />", "\n"), "").Trim()); Console.WriteLine(post.CreatedAt); Console.WriteLine("--------------------"); break; case "home": var home = await tokens.Timelines.HomeAsync(); Console.WriteLine("--------------------"); foreach (var status in home) { Console.WriteLine(status.Account.DisplayName + "\t\t" + status.Account.Acct); Console.WriteLine(TagRegex.Replace(status.Content.Replace("<br />", "\n"), "").Trim()); Console.WriteLine(status.CreatedAt); Console.WriteLine("--------------------"); } break; case "ftl": var ftl = await tokens.Timelines.PublicAsync(); Console.WriteLine("--------------------"); foreach (var status in ftl) { Console.WriteLine(status.Account.DisplayName + "\t\t" + status.Account.Acct); Console.WriteLine(TagRegex.Replace(status.Content.Replace("<br />", "\n"), "").Trim()); Console.WriteLine(status.CreatedAt); Console.WriteLine("--------------------"); } break; case "ltl": var ltl = await tokens.Timelines.PublicAsync(local => true); Console.WriteLine("--------------------"); foreach (var status in ltl) { Console.WriteLine(status.Account.DisplayName + "\t\t" + status.Account.Acct); Console.WriteLine(TagRegex.Replace(status.Content.Replace("<br />", "\n"), "").Trim()); Console.WriteLine(status.CreatedAt); Console.WriteLine("--------------------"); } break; case "notification": var notifications = await tokens.Notifications.GetAsync(); Console.WriteLine("--------------------"); foreach (var notification in notifications) { Console.WriteLine(notification.Account.DisplayName + "\t\t" + notification.Account.Acct); Console.WriteLine(notification.Type); if (notification.Type == "mention" || notification.Type == "reblog" || notification.Type == "favourite") { Console.WriteLine("=========="); Console.WriteLine(notification.Status.Account.DisplayName + "\t\t" + notification.Status.Account.Acct); Console.WriteLine(TagRegex .Replace(notification.Status.Content.Replace("<br />", "\n"), "").Trim()); Console.WriteLine("=========="); } Console.WriteLine(notification.CreatedAt); Console.WriteLine("--------------------"); } break; } } }