Unleash the Power of Social Media

Submit New Article

retweet
February 3, 2010 11:00 PM PST


Introduction

As a game developer, imagine this situation happening to your users: You're playing a great multiplayer game and want to easily arrange games with your friends. The only problem is some of your friends aren't a part of your favorite gaming community. When you get home, you boot up your favorite game and find that none of your friends are on line. No problem, you send some IMs, emails and texts, then sign on to a few game networks; what a pain! Imagine if the game could contact your friends for you! Services like Steam*, XFire*, GamerDNA*, and Raptr* exist, but all these services presume that the friends who you'll be gaming with are already using their service. Wouldn't it be great if your favorite multiplayer game made this notification automatically, without you having to install and run specialized software?

For game developers looking to broaden their audience base, social media sites present a big market expansion opportunity. Sites like Twitter* and Facebook* have a much broader audience than niche services directed at gaming. In August 2009, Twitter had 66 million unique visitors generating 4 billion page views [1]. By leveraging social media sites from within your game, you not only connect existing users, but help them introduce it to their friends (your future customers).


Let's get to it already!

So now you understand the "why" - the rest of the article is devoted to the "how." I will walk through some code (implemented in C#) for enabling the basic functionality needed to send Tweets through PC games.

private void tweetBasicAuth(string myMessage)
{
//this is the URL where a user sends an update
string tweetURL = "http://twitter.com/statuses/update.xml?";

//building out the querystring to include the message in the status field
string tweetMsg = tweetURL + "status="+ myMessage;

HttpWebRequest tweetRequest = (HttpWebRequest)WebRequest.Create(tweetMsg);
tweetRequest.Method = WebRequestMethods.Http.Post;

//Set the username and password from where it is stored
//Reminder: passwords should be accessed as little as possible
tweetRequest.Credentials = new NetworkCredential(textBoxUsername.Text, textBoxPasswd.Text);

tweetRequest.ContentType = "application/x-www-form-urlencoded";

try
{
//If the response is normal, we close it.
//If it generates an exception we handle it in the catch.
HttpWebResponse tweetResponse = (HttpWebResponse)tweetRequest.GetResponse();
tweetResponse.Close();

}
catch (Exception e)
{
//Put your exception catching code here.
//A bad username/password will generate a 401 response
//resulting in this exception being thrown.
MessageBox.Show("Exception Generated: " + e.Message);

}
}

This simple block of code takes the message that you would like to Tweet as an argument and publishes it to the user's Twitter account. It assumes the program has access to the username and password for the account to be updated. It uses basic authentication which puts the user's credentials in the header of the http request. Although this approach is simple, putting that information into the http header is not secure. A more secure method is to use OAuth as detailed here.

One problem encountered with Twitter is that in order to avoid over usage or spam, it has filters that eliminate redundant messages. I found that even toggling between two messages ("Mitch is playing a PC Game" / "Mitch is not playing a PC Game") would not make it through the redundant message filter. Unfortunately, the timeline for these is fairly long so if with the above example I started a game and exited for some reason, and then started within the next hour, my tweets saying that I was playing the game would not appear. A simple solution is to automatically append a unique string, like a timestamp, to the end of the message.



Figure 1. Tweeting from your game is as simple as putting together an appropriate http-post!


Extending from Twitter to Facebook

Now that you've written Twitter integration into your game, your end-users can Tweet automatically at checkpoints that you've defined. Of course you're wondering how to do the same thing with Facebook status updates. One option is to use the Facebook API and separately integrate that functionality into your game. An alternative would be to educate and encourage your end-users to utilize existing services that push/pull data between Facebook and Twitter. Essentially by enabling updates to Twitter, your users can get Facebook status updates "for free." One of the many articles on how to push or pull status updates between Twitter and Facebook is here.


Take it and make it yours!

In the scenario laid out at the beginning of this article I advocated for a usage model that sends a Tweet when the player starts your application, but that is only the most basic scenario. I hope that by illustrating how easy it is to Tweet from a PC application, you will innovate on a diverse range of usage models that your players find fun and valuable. Go forth and leverage the reach of social media sites to increase awareness of your PC game!


About the Author

Mitch Lum received his bachelors, masters, and PhD from the University Of Washington, Department of Electrical Engineering. His academic work focused on the development of a telesurgery system named Raven. He is currently in the Rotation Engineer's Program at Intel in the Visual Computing Software Division.