Monday, June 24, 2013

How to Host Your Twitter Archive on Google Drive — and Keep It Automatically Refreshed

I recently made an online public archive of every tweet I’ve ever posted, that automatically keeps itself up to date:

My online Twitter archive—click to view

Setting up this up was surprisingly easy—even for a non-technical person. I’m sharing the steps below, so you can try it out yourself.

Admittedly, this is not really a useful thing to do, other than to satisfy your introspective curiosity.

But sometimes trivial pursuits are amusing (how many times have I posted about Waffle House, anyway?).

Step 1: Download your Personal Twitter Archive

Twitter lets you download a complete snapshot of all your past tweets, with an index that you can browse, search, and analyze offline.

It’s simple—follow Twitter’s instructions on downloading your archive.

Twitter will then e-mail you a link to a zip file. Download and unzip the resulting file. This creates a local folder called tweets which contains your exported archive, in two formats: CSV (comma separated value), and a JSON export with all the corresponding metadata—a full representation of all your tweets as returned by the Twitter API.

A look inside the 'tweets' folder. Open the index.html file to browse the archive 
To access the archive, open the index.html file using any browser—double click it, or use File-Open from inside your browser (Alternately, use the CSV file to import the archive into the spreadsheet or database of your choice).

Step 2: Upload the Archive to Google Drive and Share It 

Did you know that you can host webpages and images using Google Drive? You can. [see update note below]

This functionality is super handy for a mini-project like this one (I’m also using Google Drive to host the images for my map sites). There’s potential for all kinds of possibilities here which I have yet to explore fully. And it’s free. I learned about the idea for doing this via Kevin Marks.

You’ll need a Google account to do this, obviously.

1. Log in to Google via Gmail (or whatever your preferred entry point for Google is). Click the 'Drive' option in the top menubar.

2. Upload the entire tweets folder (from Part 1 above) to your Google Drive (it doesn’t have to be at the root level, incidentally).


3. Share the uploaded tweets folder as 'Public on the web' using the Share button. (Checkmark it in the document list, then press the Share button)


4. Copy the 'Link to share' text. Paste this text into an editor (Notepad, Textedit, or whatever is handy).


5. The text will contain a long string of characters that looks like what’s shown above (first line). Take this string of characters, and append it after this URL:
googledrive.com/host/

You'll wind up with something that looks like:
googledrive.com/host/0BwadvTiFXSLcU1Y4YVVybjJGekU

This ungainly address is the web link for your online twitter archive, which you can now share with anyone you like. Keep in mind that the archive is now public on the internet, and theoretically discoverable.

You can use an URL shortener like bit.ly to mask the ugly web address if you’re so inclined.

Update: Unfortunately, Google announced that it will be deprecating web hosting via Drive after Aug. 31, 2016. So the above URL won’t work after that date. Instead you can use this URL instead:

https://script.google.com/macros/s/AKfycbwrXr8ejYjHwGEO6kj8f4WHIh096ARDRHdNOgAXPqGltoa80FU/exec?folder_id=

and then append the same ID string as above. So, for example, mine will be:

https://script.google.com/macros/s/AKfycbwrXr8ejYjHwGEO6kj8f4WHIh096ARDRHdNOgAXPqGltoa80FU/exec?folder_id=0BwadvTiFXSLcU1Y4YVVybjJGekU

Note that this script is by Martin Hawksey (see below). I trust him; you’ll need to make your own judgment on that.

Step 3 (Optional): Set up a Script to Automatically Synchronize the Archive

Without some mechanism for periodically updating it with new tweets, your archive will only reflect posts up to the moment when you download it. Which obviously is not an entirely satisfactory state of affairs.

To rectify this, set up a Google Drive script to monitor your tweets and update the archive automatically. That might sound tricky, but luckily for you, someone else has already done that work.

Martin Hawksey has created an excellent Google Docs spreadsheet implementing such a script, along with instructions on how to get it running.

Follow Hawksey’s instructions to set things up.

You can inspect the code if you want, to verify what the script does. Along the way, you’ll be creating a Twitter app! [Note: the instructions are clear enough so that non-developers can successfully complete them; you merely have to follow the steps.]

The end result: a self-updating, online archive of your entire Twitter history. You can configure the script to update at an interval of your choice; I set mine to run once every morning in the wee hours, but you may prefer a faster or slower synchronization schedule.

Is this worth doing? Perhaps. Perhaps not. Despite the general banality of most tweets, a person’s personality and interests do get expressed to a certain degree by what they tweet. By examining your posting history, you might gain insight into your own mindset and weltanschauung.

Good luck, and enjoy your archive. Share it with me in the comments if you like!

See also
Twitter Omphaloskepsis
If This, Then That—Connecting the Semantic Web