|
AdditionalFeatures
More features for painless Twitter client development
Data classes You can deserialize all JSON response strings into data classes fast and easily using extension methods. To use data classes with JSON results, make sure you include import/using statements for Dimebrain.TweetSharp.Model and Dimebrain.TweetSharp.Extensions.
AsUsers(), AsUser(), AsStatuses(), AsStatus(), AsDirectMessages(), AsDirectMessage(), AsRateLimitStatus(), AsError(), AsSearchResult(), AsToken(), AsTrends() Relative Time You can call the ToRelativeTime() extension method on a DateTime, such as the CreatedDate property of a TwitterStatus data class: // fetch a user's profile
var profile = FluentTwitter.CreateRequest()
.Users().ShowProfileFor(TWITTER_USERNAME).AsJson()
.Request().AsUser();
// "59 minutes ago"
Console.WriteLine(profile.Status.CreatedDate.ToRelativeTime(false));
// "fifty-nine minutes ago"
Console.WriteLine(profile.Status.CreatedDate.ToRelativeTime());Retweeting Use Retweet() rather than Update() to automatically add a retweet to your message. There are currently two supported Retweet modes, the default prefix 'RT', and the more vogue unicode 'recycler' symbol retweet.
// use the default, ie. "RT I'm an interesting update."
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
.Statuses().Retweet("I'm an interesting update.")
.AsJson();
// use a different retweeting strategy
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
.Statuses().Retweet("I'm an interesting update.", RetweetMode.SymbolPrefix)
.AsJson();Shorten URLs Shortening URLs is enabled with one line. You can shorten urls with to.m8.to, tr.im, bit.ly, is.gd, and tinyurl service providers. If you'd like support for an additional provider, just file a project issue. // with the default provider (http://to.m8.to)
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
.Configuration.UseUrlShortening()
.Statuses().Update("Here is a url I want to shorten - http://www.dimebrain.com")
.AsJson();
// with a specified provider (http://tinyurl.com)
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
.Configuration.UseUrlShortening(ShortenUrlServiceProvider.TinyUrl)
.Statuses().Update("Here is a url I want to shorten - http://www.dimebrain.com")
.AsJson();
var response = twitter.Request();Post Photos Currently, tweet# supports posting photos automatically to TwitPic and yFrog. You can post a photo with a status update or a direct message. Currently you can only add the TwitPic url as a suffix appended to the end of your message text. // without text, just posts the photo url as the status
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
.Photos().PostPhoto("failwhale.jpg")
.Statuses().Update("")
.AsJson();
// with text, posts the text, then the photo url (via yFrog, not TwitPic)
// i.e. "Awesome! - http://yfrog.com/1234"
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
.Photos().PostPhoto(SendPhotoProvider.YFrog, "failwhale.jpg")
.Statuses.Update("Awesome!")
.AsJson();
// send a photo with a direct message
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs(TWITTER_USERNAME, TWITTER_PASSWORD)
.Photos().PostPhoto("failwhale.jpg")
.DirectMessages.Send(TWITTER_RECIPIENT, "This is hilarious!")
.AsJson();
var response = twitter.Request();
|
Sign in to add a comment