-
Notifications
You must be signed in to change notification settings - Fork 48
Quick Tutorial
To authorize a new account, call OAuth.Authorize(string, string) .
var s = OAuth.Authorize("consumer_key", "consumer_secret");OAuth.Authorize returns an instance of OAuthSession.
To get the authorize url, use OAuthSession.AuthorizeUri.
Console.WriteLine("access here: {0}", s.AuthorizeUri);Get and submit a pin code to get a oauth token.
var t = s.GetTokens("PINCODE");Your first tweet.
In CoreTweet, you can specify parameters using lambda expressions.
t.Statuses.Update(status => "hello");View your home timeline.
Most of CoreTweet's methods returning IEnumerable<T>, you can use LINQ methods to filter it.
foreach(var status in t.Statuses.HomeTimeline(count => 50).Where(x => x.Text.Length > 60))
Console.WriteLine("long tweet by {0}: {1}", status.User.ScreenName, status.Text);The implementation of the streaming API is very simple.
There is almost no differences between using the user stream and public stream.
To use streaming, you must cast the message by the type of the message.
This is good for several .NET languages that supports pattern matching(such as F#, Nemerle), not for C#.
But, for C# users, you can easily check the type of messages for checking the MessageType member.
foreach(var m in t.Streaming.User())
{
switch(m.MessageType)
{
// I think this code is still better than to specify delegates
// on starting stream ( User(x => Show(x), null, null, null, null ...) ).
case MessageType.Status:
var status = (m as StatusMessage).Status;
Console.WriteLine("{0}: {1}", status.User.ScreenName, status.Text);
break;
default:
break;
}
}Use Filter() to receive a filtered stream.
foreach(var m in t.Streaming.Filter(track => "tea"))
.OfType<StatusMessage>()
.Select(x => x.Status)
.Take(10))
Console.WriteLine("about tea by {0}: {1}", m.User.ScreenName, m.Text);You can also use streaming API with Reactive Extensions.
var stream = t.Streaming.UserAsObservable().Publish();
stream.OfType<FriendsMessage>()
.Subscribe(x => Console.WriteLine("your friends: " + string.Join(", ", x)));
stream.OfType<StatusMessage>()
.Subscribe(x => Console.WriteLine("{0}: {1}", x.Status.User.ScreenName, x.Status.Text));
var disposable = stream.Connect();
await Task.Delay(30 * 1000);
disposable.Dispose();