I'm trying to implement a feature in a .Net WPF application to automatically display photos from twitpic when users post them to my hashtag.
I'm using the Twitterizer2 API library, all the tweets coming from my search have their links as t.co links (I think this is from Twitter). I don't know how to parse these links to get the images to send them to the users.
I don't know how Twitterizer2 API works but I think you could solve your problem in two ways:
For the second approach I would suggest something like the function below (this parsing is based on the first picture I have found on my followed people tweets so it works only for TwitPic images):
private static Uri GetPicture(string twitterUri)
{
using (var webClient = new WebClient())
{
string html = webClient.DownloadString(twitterUri);
int imgIndex = html.IndexOf("<img class=\"photo\" id=\"photo-display\"");
int srcStartIndex = html.IndexOf("src", imgIndex) + 5;
int srcEndIndex = html.IndexOf("\"", srcStartIndex);
string imgSrc = html.Substring(srcStartIndex, srcEndIndex - srcStartIndex);
return new Uri(imgSrc);
}
}
As you could imagine the usage is:
Uri imgUri = GetPicture("http://t.co/RQu9hZn8"); // this is a real image