Created
March 22, 2016 14:52
-
-
Save oyakodon/4fdb72b93081efc96568 to your computer and use it in GitHub Desktop.
Simple Twitter Client / C# Console
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 CoreTweet; // NuGetからインストールできます(使用したのはVer. 0.6.1.267) | |
using CoreTweet.Streaming; | |
namespace simpleTwitter | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// トークン設定 | |
// 自分のアプリ | |
var con_key = ""; | |
var con_sec = ""; | |
// 自分のユーザ | |
var acc_key = ""; | |
var acc_sec = ""; | |
// トークンを創造(Create)する | |
var tokens = Tokens.Create(con_key, con_sec, acc_key, acc_sec); | |
// 古い形式らしいけど気にせずに使用 | |
var stream = tokens.Streaming.StartStream(StreamingType.User); | |
// 一番上はなんか綺麗にしたい。 | |
var line = ""; | |
for ( var i = 0; i < 30; ++i ) | |
line += "-"; | |
Console.WriteLine(line); | |
Console.WriteLine(" Simple Twitter Client"); | |
Console.WriteLine(line); | |
Console.WriteLine(); | |
line += line; | |
foreach ( var message in stream ) | |
{ | |
if ( message is StatusMessage ) | |
{ | |
// ツイートを取得して | |
var status = (message as StatusMessage).Status; | |
// ユーザ名とID、ツイート内容を表示 | |
Console.Write(string.Format("{0} (@{1}) :\n ", status.User.Name, status.User.ScreenName)); | |
var text = status.Text; | |
for(var i = 0; i < text.Length; ++i ) | |
{ | |
Console.Write(text[i]); | |
if ( i != 0 && i % 40 == 0 ) | |
{ | |
Console.Write("\n "); | |
} | |
} | |
Console.WriteLine(); | |
// 上だけじゃなく、下の表示も綺麗にしたい | |
Console.WriteLine(); | |
Console.WriteLine(line); | |
Console.WriteLine(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
気にして
にしてください!