Skip to content

Instantly share code, notes, and snippets.

@ustreamer-01647
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ustreamer-01647/ec906309227296bcfb26 to your computer and use it in GitHub Desktop.
Save ustreamer-01647/ec906309227296bcfb26 to your computer and use it in GitHub Desktop.
トークンの有効性を CoreTweet.Tokens.Account.VerifyCredentials() で確認する
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("_", "__");
}
}
}
@ustreamer-01647
Copy link
Author

CoreTweet: CoreTweet.Rest.Account Class Reference
UserResponse CoreTweet.Rest.Account.VerifyCredentials ( params Expression< Func< string, object >>[] parameters )
Returns a representation of the requesting user if authentication was successful.
Use this method to test if supplied user credentials are valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment