How to create an automatically updating Google spreadsheet

Tired of finding, copying and pasting data into spreadsheets? With just a few lines of code, you can set up a self-updating spreadsheet in Google Docs that fetches and stores data for you, as this Facebook example shows. Update: Due to changes in Facebook's social graph, this code no longer works. Instead, see how to do the same thing with Twitter followers.