/// <summary> /// 自分のアカウントを取得し、メニューバーに表示 /// </summary> /// <returns></returns> private async Task SetMyAccounts() { try { if (TwitterTokens != null) { var tweet = (await TwitterTokens.Statuses.UserTimelineAsync())[0]; var text = $"{tweet.User.Name}(@{tweet.User.ScreenName})".Replace("_", "__"); // アンダーバーをエスケープ Dispatcher.Invoke(() => twitterAccountMenuItem.Header = text); } } catch (Exception e) { MessageBox.Show("Twitterのアカウントを読み込む際にエラーがでました。\n再認証してください。\n" + e.Message); TwitterTokens = null; } try { if (PawooClient != null) { var user = await PawooClient.GetCurrentUser(); var text = $"{user.DisplayName}(@{user.AccountName})".Replace("_", "__"); // アンダーバーをエスケープ Dispatcher.Invoke(() => pawooAccountMenuItem.Header = text); } } catch (Exception e) { MessageBox.Show("Pawooのアカウントを読み込む際にエラーが出ました。\n再認証してください。\n" + e.Message); PawooClient = null; } }
private void AuthPawooFromFile() { var accessToken = System.IO.File.ReadLines(TokenFilePathPawoo).ToArray()[0]; var appRegistration = new Mastonet.Entities.AppRegistration { Instance = "pawoo.net", ClientId = Properties.Resources.PwClientKey, ClientSecret = Properties.Resources.PwClientSecret }; PawooClient = new Mastonet.MastodonClient(appRegistration, new Mastonet.Entities.Auth { AccessToken = accessToken }); }
public async Task MastodonAuthTest() { var moe = new Moe(); foreach (var mastodonAuthSet in moe.MastdonAuthSet) { var client = new Mastonet.MastodonClient( mastodonAuthSet.AppRegistration , mastodonAuthSet.AccessToken); var currentUser = await client.GetCurrentUser(); currentUser.IsNotNull(); Console.WriteLine(mastodonAuthSet.AppRegistration.Instance); Console.WriteLine(currentUser.AccountName); Console.WriteLine(currentUser.DisplayName); Console.WriteLine(); } }
/// <summary> /// メニューアイテムの認証→Pawooをクリックした時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void AuthPawooMenuItem_Click(object sender, RoutedEventArgs e) { try { var appRegistration = new Mastonet.Entities.AppRegistration { Instance = "pawoo.net", ClientId = Properties.Resources.PwClientKey, ClientSecret = Properties.Resources.PwClientSecret }; var authClient = new Mastonet.AuthenticationClient(appRegistration); var authWindow = new AuthWindow(authClient.OAuthUrl()); authWindow.ShowDialog(); if (authWindow.isOk) { var accessToken = await authClient.ConnectWithCode(authWindow.pin); PawooClient = new Mastonet.MastodonClient(appRegistration, accessToken); // Save Token using (var sw = new System.IO.StreamWriter(TokenFilePathPawoo)) { sw.WriteLine(accessToken.AccessToken); } // タイムラインのロード foreach (var s in await PawooClient.GetHomeTimeline()) { pawooTimelineStackPanel.Children.Add(new Toot(s)); } } } catch (Mastonet.ServerErrorException ex) { MessageBox.Show(ex.Message, "エラー"); return; } await SetMyAccounts(); }