At long last here's the import script I used: import-flickr-photos.php
If you want to try it out, be sure to add all of your personalized information I've mentioned in the previous steps (1
) to the top of the script.
Here's what the script does:
- Authenticates the person running the script at Flickr via the browser. (You'll have to give your script permission to read all of your photos.)
- Requests the total number of photos for the authenticated account from the Flickr API (to help with looping).
- Requests all of the account's photos, asking for standard info (title, FlickrID, whether or not it's public) and some extra details (relevant dates, and the longitude and latitude).
- Loops through every photo, adding the photo information to the database if it isn't already there.
- Downloads the original photo file from Flickr and saves it locally if it isn't already there.
- Requests the description (caption) and tags for the particular photo from the Flickr API. (Requires a separate API call, unfortunately.)
- Adds the file location, description, and tags to the db.
- Finally, the script sleeps for one second before doing anything else. (Seemed like the polite thing to do so the script doesn't hammer the API.)
In my last post I mentioned that Flickr Backup was clunky to use, but this script is a thousand times clunkier. If Flickr Backup is a Ford Taurus, then running this script is like taking your covered wagon out on the Oregon trail: no shocks, no rubber tires, no paved roads, and you'll likely die of cholera before it's finished. I'm kidding on that last part, but the script probably will die before all of your photos are saved locally. Not to worry, you can run the script multiple times without duplicating files or data. The script checks for existing records and files before taking any action. I have 513 photos at Flickr—which isn't too many in the scheme of things—and I still needed to run the script a couple times to get all of them. (I set a ridiculously high timeout at the top of the script, but the script seemed to die anyway.)
To run the script, open it in your browser. The URL should be something like:
The script will redirect you to Flickr where you'll need to log in and/or authorize the script. From there, the magic starts. The script will try to give you some info about what's happening, but if you don't see anything but a blank page, don't worry, it's probably working. If you can, log into your server and check out the photos directory you set up. You should see folders and files appearing. Another way to check progress is by firing up MySQL and running some counts on your table. Something like this:
SELECT Count(PhotoID) FROM photos
If the script is working the count will be higher than zero.
It's important to note that the import script is grabbing every photo you uploaded to Flickr
, even those marked as friends and family only. This is exactly what I wanted to happen, but if you want something different, check out the documentation for the flickr.photos.search
method and tweak line 65 of the script. You can set a
argument in the call to get a list of only photos that are public, for example.
So, once this script finished, I had a bunch of local directories filled with photos that I'd uploaded to Flickr over the past three years. I also had 513 records in the photos
table and 1,646 records in the tags
table describing those photos. That means I (and some others) added about 3.2 tags per photo. huh. So I can't really look at my photos through the Web yet, but at least they're ready for the next phase. Not too shabby for a few hours on a Saturday afternoon.
As I mentioned before, OTFG is an off-the-top-of-my-head project. So if you try any of this stuff out, please don't hold me responsible for your toaster catching on fire. I'm sharing this project publicly to show how I'm going off the Flickr grid
, and to hopefully get some feedback in the process.
Next Up: Set Theory