Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
トークンの有効性を 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

This comment has been minimized.

Copy link
Owner Author

commented Oct 12, 2014

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
You can’t perform that action at this time.