How to hook Flickr to your site via Drupal

I have a Flickr account, a personal site, alot of sad geeky experience with Drupal and a passion for tapping into APIs where I find them. Also, I wouldn't mind monetizing what I am doing. The Flickr module for Drupal is good, but I wanted to take these images and include them on my own site as nodes. Also, I wanted a process that would automatically grab images rather than making me cut and paste images into my site. Beyond this, I wanted to leave this concept open enough that I could pop in media from other sources (like Youtube). This is how to combine these elements into a whole and this may help you if you want to do the same thing.

There are some things you have go out there and find (and some I include below that):
You need to build a content type to support holding and displaying these pieces of gathered content. I built a content-type, Media, to hold a rendered copy of the image and some supporting information. The view of the page is pre-built by my node-save process. I have added a source field to hold a reference to the image; this will be checked when data is imported via the API so that you don't import multiple copies of the same image. To make this easier, I have used the Import/Export capacity to make a copy of the CCK content-type that you can import into your site.

There are TONNES of elements available from the Flickr API. In my example, I grabbed the basics of the image and then I went back and grabbed the "exif" data for these images. The Exif has the potential to hold all of your camera's data: model, resolution, palette information. In my case, I am sniffing out the model information and I have added a field called "ware" in the Media type to hold the hardware and software used to create my images. I have a product search tool tied into Shopping.com. I take this model information, stored in the "ware" field and I used it to make linkage to the shopping.com tie-in.

Next, I built a node template for this content-type. It formats the node and organizes its data. What it also does it make the linkage to the Product Search page using the ware field.

What you can do with this content-type is build a view to display the nodes. I have an export of that node: View. The view can be used as a standalone page; or use a block in a panel or another part of your layout.

How do you get your data from the API? You can build a standalone page with a bootstrap include. Or, you could build a whole module around this action. Personally, I fewer to keep my module count as low as I can get away with-- too many modules and you have a huge weight to pack around when load pages. In my case, I went the easiest route possible: I made a page and added a qualifier so that the import functionality is not easily called. If it is called additional times, the source field should save your bacon-- it will compare the images you already have vs. those seen from the API data. When you execute this code, calling media_node_flickr() will spawn the API call, the duplication check and the node saving.

You can take the code and build on it-- add new fields to the content type, add functionality, mine the API for more information.

Comments