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
- Download the script.
- Upload it to your PHP enabled web server.
- Set configuration options
- Setup a cron job to run this script as often as you want.
Configuration
The options PHP variables at the top of the file.
- 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 () 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
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.
Jeremy, you’re so dreamy. This is pretty damn cool!
[…] unknown article is brought to you using rss feeds.Here is some of the latest web hosting news.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 … […]
In what way(s) is this better/worse than Twittergram? Or, maybe the better question is what didn’t work for you with Twittergram/inspired you to do this yourself? You were a bit vague in your blog post about your motivation. 😉
Kudos, btw, not only on the app itself, but also on what appears to be either beating Winer at his game, or showing just how relatively simple his “great programming genius” is. Keep up the good work!
@Adam
Thanks for the comment and the praise. I wouldn’t say this is any better than Twittergram, just that with this you have complete control over how it works and you don’t have to give other people your twitter password.
When I originally entered my information into Twittergram and uploaded a photo to Flickr…nothing happened. After an hour, still nothing happened. It’s possible that I entered something incorrectly but it was just enough to motivate me to build my own.
Hope you like it!
This requires PHP5, yes?
Sorry for a follow up comment, but I wanted to point out that this script is subject to this PHP bug, incase anyone else gets this error.
I have not yet found a solution, but I will be rewriting this script a little to fix it.
[…] links to Flickr photos (here is my first Flickr photo that I Pownced) I knew I had to modify a script that I found and had modified for Twitter. The script would automatically “tweet” when I posted a […]
[…] few weeks ago I spotted this blog post on the Mozmonkey Blog about a mashup that could scan your Flickr feed for tags and post a link on your Twitter stream. I […]
For some strange reason, I get multiple twitter posts to the same tiny URL(photo) after I upload picture to flickr. Anyone else have this issue?