Parsing Twitpic Thumbnails From a Tweet With C#
Posted on Thursday, 31 March 2011 16:44I recently wanted to add thumbnails from twitpic when a school linked them in a tweet. Here's how I did it.
Firstly, setup this regular expression.
protected static Regex TwitpicIDs =new Regex(@"https?://twitpic.com/+([w-]+[^ ]*)", RegexOptions.Compiled);
The Regular expression will match any instances of the twitpic url in the tweet. When you have the text value of the tweet, process it like this.
string tweet = "this is a twitpic http://twitpic.com/abcdef";if (TwitpicIDs.IsMatch(formattedText)){foreach (Match match in TwitpicIDs.Matches(formattedText)){Response.Write("<img src="http://twitpic.com/show/mini/" + match.Groups[1].Value + ""/>");}}
That, as they say, is that. Once you have the twitter post, you just parse out the URL's into an array using the regular expression. If you want the full url of the image from the regular expression, just use match.Value.