Last active
August 29, 2015 14:07
-
-
Save ustreamer-01647/ec906309227296bcfb26 to your computer and use it in GitHub Desktop.
トークンの有効性を CoreTweet.Tokens.Account.VerifyCredentials() で確認する
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 testCoreTweet2 | |
{ | |
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
internal Tokens tokens; | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
// load twitter token | |
if (!string.IsNullOrEmpty(Properties.Settings.Default.AccessToken) | |
&& !string.IsNullOrEmpty(Properties.Settings.Default.AccessTokenSecret)) | |
{ | |
tokens = Tokens.Create( | |
Properties.Settings.Default.ApiKey | |
, Properties.Settings.Default.ApiSecret | |
, Properties.Settings.Default.AccessToken | |
, Properties.Settings.Default.AccessTokenSecret); | |
// トークン有効性確認 | |
try | |
{ | |
var userResponse = tokens.Account.VerifyCredentials(); | |
updatescreennameLabel(userResponse.ScreenName); | |
Properties.Settings.Default.ScreenName = userResponse.ScreenName; | |
Properties.Settings.Default.Save(); | |
} | |
catch (Exception ex) | |
{ | |
// MessageBox.Show(ex.Message); | |
tokens = null; | |
} | |
} | |
} | |
/// <summary> | |
/// スクリーンネーム表示を更新する | |
/// </summary> | |
/// <param name="screenName">Twitter Screen Name</param> | |
/// パラメータ省略時は設定ファイルを読み出す | |
internal void updatescreennameLabel(string screenName = null) | |
{ | |
string _screenName; | |
if (string.IsNullOrEmpty(screenName)) | |
{ | |
_screenName = Properties.Settings.Default.ScreenName; | |
// 未認証時 | |
if (string.IsNullOrEmpty(_screenName)) | |
{ | |
screennameLabel.Content = "unregister"; | |
return; | |
} | |
} | |
else | |
{ | |
_screenName = screenName; | |
} | |
// http://msdn.microsoft.com/ja-jp/library/system.windows.controls.label(v=vs.110).aspx | |
// WPF Labelにおける文字 _ の仕様について対策する | |
screennameLabel.Content = _screenName.Replace("_", "__"); | |
} | |
} | |
} |
Author
ustreamer-01647
commented
Oct 12, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment