Category Archives: Twickr

Flickr / Twitter Mashup = Twickr (or maybe Flitter)

I’ve been using Twitter (https://twitter.com/jgillick) for a little over a month now and the one that’s lacking is picture messaging. What I want is to upload a photo to Flickr, create a TinyUrl for it and sent that plus a short description as a Twitter update. Well now it’s possible.

After a little research I found a tool, called TwitterGram, which does just this. You enter your Flickr username and Twitter username/password and it will automatically send updates to your Twitter log when you upload a photo. Unfortunately it didn’t work for me, so I went ahead and made my own which you can download and run on your servers!

My script starts by reading the Flickr feed (rss or atom), checks for new images that were uploaded within the last 12 hours (this can be set by $timeout — see configuration), gets the TinyUrl for each new photo and sends it with the Flickr title to Twitter.

Setup

Configuration

The options PHP variables at the top of the file.

$twitter
The username/password for your twitter account
$flickr
The flickr feed URL to watch. This must be in atom or rss2 format. NOTE: RSS1.0 does not have timestamps and can cause duplicate entries or other unexpected behavior.
$cacheFile
This file holds the last 50 flickr image URLs uploaded in PHP serialized form to prevent duplicate entries.
$timeout
Filters out photos from your stream that were uploaded before this number of hours ago.
$debug
Set this to TRUE if you want to test the script and do everything but send the message to twitter.

Flickr Feed

Using a Flickr feed lets you limit the Twickr tweets to a specific tag. Here’s how to get the feed URL:

  • Login to Flickr
  • Click “Your Photos”
  • Add the following to the end of the URL “tags/twickr/” (change “twickr” to any tag you want to limit the app to)
  • Click the RSS icon (Subscribe to a feed of stuff on this page...) towards the bottom of the page.
  • The page that loads is your Flickr feed, copy that URL into your $flickr configuration variable.

Testing

Before finishing the setup be sure to test it. Edit the script and set $debug to TRUE and then run it from the command line:

php -f twickr.php

A common error will be “Permission denied” when it tries to create the cacheFile — which is used to store the URL of the last 50 images tweeted to prevent duplicates. This file is saved in the same directory as the script. Be sure the user which calls the script has access to write to this directory.

Remember to set $debug back to FALSE when you’re ready to use the script for real.

Cron Job

If you’ve never setup a cron job before, use this command:

sudo crontab -e

The to have the script (which in my case is at /usr/local/bin/twickr/twickr.php) run every 10 minutes enter the following as it’s own line:

0,10,20,30,40,50 *   *   *   *   php -f /usr/local/bin/twickr/twickr.php

(More information about cron)

Now whenever you upload a photo to flickr with the required tag it’ll automatically send a tweet with the Flickr image title and URL (as a TinyUrl).

Download

Download or get the latest from my SVN repository.

Web Service

If you do not have a web server or are want to have somebody else host the script I’m considering putting together a simple site to do just that for you. If you’re interested let me know in the comments and subscribe to my blog to hear about updates like this in the future.

Updates

Subscribe to my blog to learn about updates.