Social Coding Series: I'm In Your Social Graph, Hacking Your Life - a Howto - Stay N Alive

Social Coding Series: I’m In Your Social Graph, Hacking Your Life – a Howto

As the first entry to my Social Coding series I’m going to cover Google’s Social Graph API. I saw a demo of this at Google I/O in San Francisco and was so impressed that I immediately started hacking on it when I got home. Little did I know how powerful this API was and how much information it could pull off the web about a single individual!

Google’s Social Graph API takes a cache of the rich storage of links, information, and URLs on Google’s servers, and determines which of those contain information about actual people. It combines OpenID for confirming an individual’s identity, and XFN and FOAF XML protocols to determine links between those identities. With a simple tag on a user’s website, a user can determine other websites that also identify them. If you link to one URL identifying that location as you, and at the linked website, it links back to you, Google can tell for sure both of those websites are yours, and identify you as a person. Not only that, but you can similarly provide XFN information or FOAF information via similar tags or a separately linked file identifying who your friends are. If they link back to you via similar metadata Google can tell for sure that the two of you are friends.

The Social Graph API lives and breaths this data. There are actually quite a few Social networks that use this protocol to identify you and your friends. Sites like Digg, Twitter, and FriendFeed all utilize these protocols to identify your friends. The Google Social Graph API scans this data and organizes it in an easy way for you, as a developer, to access.

Let’s try a simple example, and you don’t even have to be a developer to try it. Google has provided a simple playground to see how the Social Graph API works. If you go to http://socialgraph-resources.googlecode.com/svn/trunk/samples/exploreapi.html, enter in a few URLs of your blogs, social networking profiles, and other identifying locations on the web, leave “Follow ‘me’ Links”, “Pretty Output” checked, and click, “Find connections”. For me, just “twitter.com/jessestay” was all I needed to enter in the textarea.

The resulting structure is organized in a format called JSON – if you’re a Perl developer you might be familiar with this, as it is formatted the same way as a Perl Hash structure. You’ll see under “nodes” a bunch of URLs with different metadata about the URL – these are URLs that Google thinks, based on the metadata in the URL you provided, are you or contain info about you. I’ve found that only those with a “profile” attribute are actual Social Network profiles for yourself, so be sure to pay attention to those.

You can also go back and click “show inbound links” and “show outbound links” – this will then return URLs with links to sites you have identified as yourself, as well as sites you own that claim other sites as identifying for you. Play around with it – there’s a wealth of information it will give you about people!

Now, if you’re not a developer, you can skip over this next section because I’m going to get technical by showing an example. I’m a Perl developer so I’ll show one in Perl.

In Perl it’s simple – you need to install Net::SocialGraph with a command similar to this:

perl -MCPAN -e “install Net::SocialGraph”

Then, a bit of code like this will give you the data you need:

my $sg = Net::SocialGraph->new(‘fme’ => 1);

my @urls = ();
push (@urls,’http://twitter.com/jessestay’);
push (@urls,’http://facebook.com/profile.php?id=683545112′);

my $res = $sg->get(@urls);
my @profiles = ();
foreach my $node (keys %{$res->{‘nodes’}}) {
  if ($res->{‘nodes’}->{$node}->{‘attributes’}->{‘profile’}) {
    push (@profiles, $res->{‘nodes’}->{$node}->{‘attributes’}->{‘profile’});
  }
}

In the above example I instanciate my $sg object, telling it to follow “me” attributes in the response. I add a couple URLs to identify the individual I want profile information for (in this case, me), and then make the call to the SocialGraph API to go get my info based on those URLs with the “get” method provided by the API. Then, I just traverse the response and I can do whatever I want with it. After this, I could take the response information and list all of the user’s profiles as links, or perhaps I could scan those profiles for more information and provide information about each identified profile. You’ll also note that it’s not always correct so you’ll want to let the user intervene. Also, note I’m looking for only links with a “profile” attribute – I’ve found these to be most accurate.

Beyond that, that’s it. Ideally, you could take the Playground example above and look at the resulting URL. The basics of the Social Graph API are just that URL – plug in whatever you want and you’ll get back whatever information you need. You could then parse it with Javascript, Perl, PHP, or just leave it in the “pretty” format the Playground provides you by default.

Now, imagine taking that data and combining it with, say the Twitter API to pull out all of an individual’s friends on Twitter, then applying the Social Graph API to each of those individuals. Soon, you have a tool which can identify which of a user’s friends are on which networks, and if there are any of your friends you have not yet added on those networks. This API is powerful!

The Social Graph API can be an excellent utility to find out more information about any individual using your applications. No longer do you have to ask the individual for that information – so long as they are active on Web 2.0 that information can be provided for them to choose from!

You can learn more about the Social Graph API here.

Please note I too am new to this API – any inaccuracies in this document please let me know in the comments and I will correct them for others to benefit.


Discover more from Stay N Alive

Subscribe to get the latest posts sent to your email.

One thought on “Social Coding Series: I’m In Your Social Graph, Hacking Your Life – a Howto

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from Stay N Alive

Subscribe now to keep reading and get access to the full archive.

Continue reading