Tweet Nest and Instagr.am, sitting in a tree …

Last month I’ve set up Tweet Nest, a browsable, searchable and easily customizable archive and backup for your tweets, at https://www.bram.us/tweets/ in order to have a local archive of all (*) my tweets. More recently I’ve started using Instagr.am, an instant photos sharing app for the iPhone (with Twitter, Facebook & Flickr integration). Now, what if the two would play nice together?

What I like about Tweet Nest is that it sports detection for sites like TwitPic, Yfrog, img.ly, imgur, etc: if an image is detected in the tweet, the image will be shown inline next to the tweet:


Tweet Nest detects images, and shows ‘m inline

As Instagr.am is fairly new, Tweet Nest doesn’t support it. Yet. As Tweet Nest is written in PHP, it was no biggie for me to dive into the (rather cluttered) code and add support for Instagr.am to it. The code below will add Instagr.am detection for newly retrieved tweets: if an instagr.am link is found, it’ll extract the photo from it.

A code insertion need to be done in the file extensions/images.php. First, locate the following code snippet in the file (the closing curly bracket should be on line 46):

[php]if($domain == “twitvid.com”){
$imgs[$link] = “http://images.twitvid.com/” . $imgid . “.jpg”;
}[/php]

After that, insert the following code:

[php]if($domain == “instagr.am”){
$html = (string) getURL($link);
preg_match(‘//i’, $html, $matches);
if (isset($matches[0]))
{
$imgs[$link] = substr($matches[0], 35, -3);
}
}[/php]

Update: Just noticed that Instagr.am also allows dashes (-) in their IDs. Therefore one other tiny adjustment needs to be done. On line #8 of extensions/images.php replace:
[php]preg_match(“@/([a-z0-9]+).*@i”, $path, $m);[/php]

with the following:

[php]preg_match(“@/([a-z0-9\-]+).*@i”, $path, $m);[/php]

Savvy users will see that the code above is quite a nasty thing: fetch the Instagr.am page and extract the image from the HTML. Yes, scraping. Urgh.

I hope to change the code above to something nicer any time soon but that can only happen when Instagr.am adds support to having simple (redirect) URLs to fetch the thumbnails, just as TwitPic, Yfrog and many other services offer. If you feel my pain, please vote up the corresponding issue on the Instagr.am Getsatisfaction page.

Anywho, if all goes well, the result should be something like this:


TweetNest, with Instagr.am integration

Please note that this fix will only work for newly retrieved tweets, and not for the current ones imported (unless one tells me a way to re-parse all previously fetched tweets again)

That’s it … for now 😉

(*) Actually not all tweets were backed up. The first fetch only got 3200 tweets, as limited by Twitter itself.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.