Skip to content

Instantly share code, notes, and snippets.

@oyakodon
Created March 22, 2016 14:52
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 oyakodon/4fdb72b93081efc96568 to your computer and use it in GitHub Desktop.
Save oyakodon/4fdb72b93081efc96568 to your computer and use it in GitHub Desktop.
Simple Twitter Client / C# Console
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();
}
}
}
}
}
@azyobuzin
Copy link

// 古い形式らしいけど気にせずに使用
var stream = tokens.Streaming.StartStream(StreamingType.User);

気にして

var stream = tokens.Streaming.User();

にしてください!

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