Hacking the Facebook Developer API

Sunday, June 3rd, 2007

It’s been a while since I’ve written very much code just for myself, rather than everyone else. So this weekend I’ve decided to jump onto the Facebook API and learn a little bit more about the Gallery2 API in the process.

Why?

I have thousands of photos on Blakepics, and Facebook comes along and wants me to upload them all over again. Well, sure, I can do that – or, it makes a lot more sense to combine the power of the two systems.

What?

Wanting to keep this initial trial run extremely simple – I’ve gone for just adding a link below my profile picture. That way I can keep very clear of the Gallery API for the time being effectively reducing my problems by half :)

How?

  1. User adds the Blakepics application on Facebook
  2. Setting the Callback URL on Facebook, a request is made to Blakepics.com
  3. Blakepics.com makes use of the Facebook API to check the currently logged in user
    // the facebook client library
    include_once('../modules/facebooktaggedalbums/api/client/facebook.php');
    include_once('../modules/facebooktaggedalbums/api/client/facebookapi_php5_restlib.php');
    // some basic library functions
    include_once('../modules/facebooktaggedalbums/api/lib.php');
    // this defines some of your basic setup
    include_once('../modules/facebooktaggedalbums/api/config.php');
    $facebook = new Facebook($api_key, $secret);
    $facebook->require_frame();
    $user = $facebook->require_login();
  4. Using this user ID, Blakepics requests the first and last name of that user from Facebook
    $user_info = $facebook->api_client->users_getInfo ($user, 'first_name,last_name');
  5. Generate a URL that links to the tagged album, e.g. http://www.blakepics.com/key/kevin+blake. Using the rather cool FBML (FaceBook Markup Language), the link can be sent to Facebook with the instruction that this should be applied as a profile action (fb:profile-action).
    $fbml="<fb:profile-action url=\"http://www.blakepics.com/key/" . $user_info[0]['first_name'] . "+".$user_info[0]['last_name']."\">View more Photos of me at Blakepics</fb:profile-action>";
    $facebook->api_client->profile_setFBML($fbml, $user);
  6. And display a message back to the user, to let them know what’s happened
    print "Blakepics profile link has been added";

And that’s it really. Obviously there’s a lot more that can be done, but the simple application works and is on its way to approval from the Facebook team. All being well, you should be able to add your own links to tagged albums very shortly.

Gallery Tagging and Web X.0

Saturday, March 17th, 2007

Flickr’s had some really quite cool tagging facilities for quite some time now. In this day and age, it’s not enough to put something on the web. Anyone with AOL Website Builder can do that (and sadly, they do). The Semantic Web is all the rage now. You need to be embrace it if you’re going to be part of the the hip crowd of Web 2.0. Or is that for Web 3.0? I forget.

We’ve always had keywords, the meta content for your pages to help search engines out in finding your content. But that just doesn’t cut it any more. Nowadays you have be tagged or labelled, dynamic, geographically aware, mash-up your own content with a multitude of other sites, bleed ajax from your eyeballs, stay mobile, accessible, interactive, and generally ensure that no two-visits to your site are ever exactly the same. If you’re not achieving that quite frankly – you’re terribly 1.0, and I’m afraid – nobody.

So imagine my excitement when I heard the news that Gallery the leviathan behind Blakepics was going to be making more use of the beloved photo keywords, not just for search – but in a Flick-esque, semantic, ever-evolving keyword extravaganza. If this was excitement, then I was feeling it. After a long wait, and drooling over alphas, betas and release candidates – the dream has been made a reality, and the wait is finally over.

So, I now have the ability to supplement my standard albums with dynamic ones. Photos of Christmas in London can now be a part of both the Christmas and London “albums”. Dynamic albums showing off all the llamas, no matter where I saw them, or holidays, europe, america, mobile phone pictures. This has also introduced the keyword “cloud” at the bottom of every page, which not only gives a way of seeing the albums, but which keywords are the most popular.

It’s not the only addition / improvement of course – but it’s one I’ve been looking forward to for a very long time :)

Geo-tagging the universe, one step at a time…

Sunday, October 1st, 2006

I’ve recently brought myself a Track Stick, after Ben pointed them out on thinkgeek.com. Believe it or not, the purpose of this purchase was not to attach it to the underside of a family members car, nor will I be attempting to covertly attach it to employees feet to verify that they’re are just going across the river for some lunch and not in actual fact going for an interview somewhere else.

In fact, it’s far less sinister than all of that, to track my holidays, places I’ve been, and more importantly – the photos I take whilst I’m there. Geotagging, or geocoding has received quite a lot of press lately, since Flickr have introduced it into their service.

I took the Track Stick into London at the weekend, for a trial run before Croatia later this month. The concept is quite simple. The GPS device records your co-ordinates alongside the time and date. The camera records the time and date when you took the photo. Once you’re back home on your PC, you can use these two pieces of information to automatically add co-ordinates into each of your photos’ EXIF headers (metadata). From there, it gets really fun :)

  • View your photos on a map like Google Earth.
  • Search for your photos based on location.
  • Find other photos that were taken in a similar area.
  • Automatically create descriptions of your photos based on how other people describe theirs of the same place.
  • Use all of those photos to construct 3D models of your holiday.

Okay, the technology isn’t all there, yet. But the important thing is to start gathering this data and to certainly make what use of it you can. So, that’s what I’ve done :)

How to tag your photos

  1. You’re going to need a GPX track file, like the one here. The bare minimum you need is the latitude, longitude and date/time. Sadly, my Track Stick won’t output this by default. So I had to create a small script to make one from the CSV format it does supply. If you’re in a similar position, you can download my quick hacked together perl script to create your own. I may improve on this in the future, but for now it works.
  2. Secondly, I used a small application called WMMX Location Stamper.
  3. Click on Photos -> Add Photos, and select all the photos you want to tag.
  4. Click on Tracks -> Add Tracks…, and load the file you’ve created as above (or obtained elsewhere if you’re not using a Track Stick).
  5. Click the Apply Tracks button on the bottom, and you’re done – geotagged photos.

Viewing your photos in Google Earth

Using Picasa2, you can save your photos in a Google Earth file and share your entire journey with your friends and family.

  1. Just load your photos into Picasa2 (File -> Add folder to Picasa)
  2. Select the photos you have just added
  3. Click Tools -> GeoTag -> Export to Google Earth
  4. Select a location, where you want to save your file.

Gallery2 / Blakepics

Finally, all of these photos can tie into Gallery2 (which is what I’ll be doing) using the existing Google Maps Module, or watch this space on Tadek’s blog, for a really promising looking module to view locations on single images.

Useful Resources

I came across a number of other useful little applications out there, which while weren’t directly useful to me – might be very helpful to you, so here they are :)

  • WMMX Location Stamper – Stamp your photos with GPS information. Totally Free.
  • Google Earth – The best way to view your photos afterwards ;)
  • Grazer - Another GPS stamping application
  • GPS Visualizer – A great online tool to sort our your GPX files, and much more.
  • Photo Studio – John Hawkins’ explanation of geotagging with Photo Studio.
  • GPS Babel – Converts your GPS track files between loads of different formats (though wouldn’t play nicely with the track stick – let me know if you have more luck!)
  • Robo Geo – nice tagging tool, but it’s a pay-for software and doesn’t really do the job any better than the rest of them.