Last active
August 29, 2015 14:06
-
-
Save ustreamer-01647/a3c52b6305b2ca938c36 to your computer and use it in GitHub Desktop.
testCoreTweet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="testCoreTweet.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="MainWindow" Height="431.182" Width="664.773" Closing="Window_Closing"> | |
<Grid> | |
<Button x:Name="startSettingButton" Content="startSetting" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="99" Click="startSettingButton_Click"/> | |
<Label Content="Access here:" HorizontalAlignment="Left" Margin="114,10,0,0" VerticalAlignment="Top" Width="88"/> | |
<TextBox x:Name="pinUritextbox" HorizontalAlignment="Left" Height="23" Margin="207,10,0,0" VerticalAlignment="Top" Width="440"/> | |
<TextBox x:Name="pinTextbox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="67,48,0,0"/> | |
<Label Content="PIN:" HorizontalAlignment="Left" Margin="10,48,0,0" VerticalAlignment="Top" Width="52"/> | |
<Button x:Name="pinButton" Content="certificate" HorizontalAlignment="Left" Margin="207,47,0,0" VerticalAlignment="Top" Width="89" Click="pinButton_Click"/> | |
<TextBox x:Name="pinResultTextbox" HorizontalAlignment="Left" Height="23" Margin="329,48,0,0" Text="pinResultTextbox" VerticalAlignment="Top" Width="318"/> | |
<TextBox x:Name="timelineTextbox" HorizontalAlignment="Left" Height="169" Margin="10,105,0,0" Text="TextBox" VerticalAlignment="Top" Width="637" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"/> | |
<Button x:Name="showTimelineButton" Content="showTimeline" HorizontalAlignment="Left" Margin="10,76,0,0" VerticalAlignment="Top" Width="113" Click="showTimelineButton_Click"/> | |
<Button x:Name="webbrowserButton" Content="webbrowser" HorizontalAlignment="Left" Margin="10,279,0,0" VerticalAlignment="Top" Width="113" Click="webbrowserButton_Click"/> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
using CoreTweet; | |
namespace testCoreTweet | |
{ | |
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
CoreTweet.Tokens tokens; | |
CoreTweet.OAuth.OAuthSession session; | |
const string ApiKey = ""; | |
const string ApiSecret = ""; | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
// load twitter token | |
if(!string.IsNullOrEmpty(Properties.Settings.Default.AccessToken) | |
&& !string.IsNullOrEmpty(Properties.Settings.Default.AccessTokenSecret)) | |
{ | |
tokens = Tokens.Create( | |
ApiKey | |
, ApiSecret | |
, Properties.Settings.Default.AccessToken | |
, Properties.Settings.Default.AccessTokenSecret); | |
} | |
} | |
private void startSettingButton_Click(object sender, RoutedEventArgs e) | |
{ | |
session = OAuth.Authorize(ApiKey, ApiSecret); | |
pinUritextbox.Text = session.AuthorizeUri.ToString(); | |
} | |
private void pinButton_Click(object sender, RoutedEventArgs e) | |
{ | |
tokens = session.GetTokens(pinTextbox.Text); | |
pinResultTextbox.Text = tokens.ToString(); | |
} | |
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) | |
{ | |
if (tokens != null) | |
{ | |
Properties.Settings.Default.AccessToken = tokens.AccessToken; | |
Properties.Settings.Default.AccessTokenSecret = tokens.AccessTokenSecret; | |
Properties.Settings.Default.Save(); | |
} | |
} | |
private void showTimelineButton_Click(object sender, RoutedEventArgs e) | |
{ | |
timelineTextbox.Clear(); | |
foreach (var status in tokens.Statuses.HomeTimeline()) | |
timelineTextbox.AppendText( | |
string.Format("{0}: {1}{2}", status.User.ScreenName, status.Text, Environment.NewLine)); | |
} | |
private void webbrowserButton_Click(object sender, RoutedEventArgs e) | |
{ | |
// http://msdn.microsoft.com/ja-jp/library/cc304466.aspx | |
session = OAuth.Authorize(ApiKey, ApiSecret); | |
System.Diagnostics.Process.Start(session.AuthorizeUri.ToString()); | |
} | |
} | |
} |
Author
ustreamer-01647
commented
Sep 17, 2014
- C# WPF初心者のCoreTweet入門1 - 01647 2014-09-15
- C# WPF初心者のCoreTweet入門2 認証 - 01647 2014-09-16
- C# WPF初心者のCoreTweet入門3 設定ファイル入出力 - 01647 2014-09-17
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment