While we wait: Leaderboard Twitter integration

Posted on August 8, 2009 - balord

(Three business days into the v1.0.1 resubmit and counting...)

In the meantime, I've been working on integrating the Snowferno Leaderboard with Twitter. Of course, that has been complicated by the DoS attack against Twitter over the last few days. But, it's coming along nicely and might even be ready to go live by the time we get our approval.

Our Twitter integration works basically like this:

  1. Players who have setup their online leaderboard account (Settings > Score Board > Edit Leaderboard Settings) can click the "Sign in with Twitter" button and allow the Snowferno Leaderboard to access their Twitter account. At the same time, we ask the bit.ly API for a shortened URL to points to that player's Leaderboard profile.
  2. Twitter sends us back OAuth tokens for that player's account, and we store those for future use. (OAuth incidentally is a really cool system. It's way too creepy these days to ask someone to give you their actual Twitter login and password. Using OAuth authentication, they only login to Twitter, whom they already trust. We avoid the security risks inherent in storing passwords, and players can revoke our app's permission whenever they want. Win/win/win (except for when Twitter throttles down OAuth to defend against DoS!))
  3. During regular online gameplay, the Leaderboard API logs certain achievements (such as getting a Top 5 score for a level... more to come).
  4. A cron script crawls the achievements log every minute and posts tweets on each player's behalf to the accounts that are Twitter-enabled. The reason I do the tweeting as a separate process was so that we could return global leaderboard data back to the game as quickly as possible.

The foundation of our integration is the PHP Twitter API wrapper twitter-async. The rest are custom additions to the Snowferno API and my Snowferno WP plugin.

Alot of the work on this has gone into getting the structures in place to gather and store authentication and making my cron script and achievements logger modular. (Also, my ongoing education in talking to APIs from inside and outside of the WordPress core.) Once the Twitter stuff is humming along nicely, I plan to delve into the Facebook Connect code and do something similar with Facebook statuses.

Leave a Reply