Whenever users sign into my application, or access its homepage, I check to see if I have recent Facebook data for them. If not, I synchronously fetch the data from Facebook. I'd do it asynchronously, but I don't want to add logic for rendering the homepage with incomplete information.
The controller code is the if statement that starts here: https://github.com/pwnall/mit_hack_2012/blob/master/app/controllers/session_controller.rb#L17
Facebook data is cached in the Profile model (each user has a profile), and in the UserFriendship model.
The model code that does the fetches is here: https://github.com/pwnall/mit_hack_2012/blob/master/app/models/profile.rb#L38
The code calls some code in the fbgraph gem to fetch profile information. It also calls the method below, which uses curl to follow redirects: