.NETからTwitterのAPIを使用するLINQ Provider(LINQ to Twitter)を使ってみます。今回は、ユーザー名とパスワードで認証して自分のタイムラインを取得しています。

LINQ to Twitter - Code Plex
http://linqtotwitter.codeplex.com/
今回はLINQ to Twitter Beta v2.0.7をダウンロードして使用

 準備

1.Twitterのアカウントを取得します。

2.「LINQ to Twitter」をダウンロードして展開、「LinqToTwitter\bin\Release」の中にある「LinqToTwitter.dll」を適当な場所にコピーします。

3.プロジェクトを作成し、「LinqToTwitter.dll」を参照に追加します。

サンプルコード(C#)

using LinqToTwitter;
static void Main(string[] args)
{
	// 認証
    ITwitterAuthorization auth;
    auth = new UsernamePasswordAuthorization() { UserName = "USERNAME", Password = "PASSWORD" };
    TwitterContext twitterCtx = new TwitterContext(auth, "https://twitter.com/", "http://search.twitter.com/");
    auth.SignOn();

    // タイムラインを取得して出力
    var tweets = from tweet in twitterCtx.Status
                 where tweet.Type == StatusType.Friends
                 select tweet;

	foreach (var tweet in tweets)
    {
    	Console.WriteLine("User Name: {0}, Tweet: {1}",
        		tweet.User.Name,
                tweet.Text);
	}
    twitterCtx.Dispose();
    Console.ReadLine();
}

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading