Senior Software Engineer & Architect. I have programmed with a variety of languages. Originally:C/C++, Mostly: Java, Occasionally: PHP, VB, Python, Unix Shell, JavaScript, Mainframe EasyTrieve and JCL. I also do Android development at the present time. Tony is a DZone MVB and is not an employee of DZone and has posted 35 posts at DZone. You can read more from them at their website. View Full User Profile

A Look at Facebook's Open Graph

05.23.2012
| 2559 views |
  • submit to reddit

A bit of history


Back in 2007, Facebook (FB) created Beacon to make it easier for users to automatically share what they were up to on sites outside of Facebook. Beacon didn't work too well mainly because of privacy considerations and poor communication from FB. Beacon was finally shut down in 2009, and the next year FB launched it's Open Graph API,  with a set of plug-ins ('Like' button, activity feed, comments, etc..) that could be simply dropped onto Web sites, making them "social objects", i.e. extensions of the FB ecosystem.

The Rise of Social Objects


What is a "social object"? Social sites are not limited to friends, they are also built around shared interests that connect people together, like the iPhone or MacIntosh, Hicking,  Cooking, Java development, etc... These can be considered 'social' objects as they help build social connections. Social objects have of course to be talk-worthy enough to bring individuals together.

FB  has expanded the social graph concept to include more than just relationships between individuals : the Web of connections is not only between people, but between things people have interest in and like to share, like a song , a game, a news article, a movie, a picture, a favorite restaurant or a cooking recipe.

Technically, social objects become nodes on a social graph, the online equivalent of a social network in the real world. These objects can eventually spread through FB's Social Channels (Timeline, News Feed, Ticker..).

The Open Graph Protocol and the Graph API


The Open Graph protocol (OGP) enables any Web page to become equivalent to a FB page, by turning to an object in FB's social graph. It is done quite simply, by placing  RDFa -formatted HTML meta tags. An OG tag has the folowing format:
<meta property="og:tag_name" content="tag_value"/>

Here's for example  how to mark up the movie "The Matrix" on imdb.com, as a social object:
<html prefix="og: http://ogp.me/ns#">
<head>
<title>The Matrix(1999)</title>
<meta property="og:title" content="The Matrix" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0133093/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/M/.../M.jpg" />
...
</head>
...
</html>

Once the object is created with OGP meta tags,  action on that object  needs to be published via the Graph API.
The Graph API  allows read-write access to the Social Graph, pending user permission for anything other than searching & reading public data. For write operations, the user gives an application an access token, and the application can publish (HTTP POST)  or delete data on that user's social graph. For read operations, an application can fetch a social object in FB's social graph by making a secure request to graph.facebook.com with the object's ID  in the Graph, to retrieve its properties in the JSON format.
There are a few Open Source Facebook Graph API written in Java, like RestFB or the lower-level BatchFB.
Here's for example, how to get the number of the Coca-Cola page fans on FB, using RestFB:
try{
  // after getting ACCESS_TOKEN from FB, 
  FacebookClient facebookClient = new DefaultFacebookClient(ACCESS_TOKEN);
  // Page Graph API type with id = "cocacola"
  Page page = facebookClient.fetchObject("cocacola", Page.class);
  // get the number of likes the page has:
  Long coca_likes = page.getLikes();
  //...
}
catch(FacebookException fex){
  // handle failure ...
}

Again, keep in mind that, for anything other than public data, even a simple fetch requires authorization by the user who needs to grant an access token to the application.



Social Object Design


We, as third parties can design Open Graph applications to do the following:
  1. Define social object(s).  For instance, YouTube has videos, Flickr has pictures. What is our product?
  2. Define the user actions associated with those objects by including the corresponding  plugin, for example a "Like" button if we want users to rate our objects, a comment box if we want them to comment, and so on.
  3. Connect the object created to the users using OGP and Social Plugins.
As much of everything becomes "social", product design does not escape that rule. Conceptually, the difficulty resides in designing objects that bring people together by sparking interest and discussions, and hence grow in the community by what would be the online equivalent of "word of mouth". Technically, all that is needed for FB integration is using plugins, OGP and the Graph API.

Conclusion


Open Graph  is a simple yet powerful technique. The FB Graph is continuously fed by the use of plugins outside of FB: "Like" button, Recommendation, Activity feed, etc... Wherever you navigate on the Web, you bring your social luggage (friends and interests) with you.

Of course, all roads lead to Rome. What FB is also doing, is recording your activity away from its site, via third parties (even when you're logged out).  So, while on the plus side it brings a lot to the Semantic Web, on the minus side, it can be seen as a service lock-in. It can be argued that Open Graph is an important step away from actual lock-in, in the sense that third parties don't need a brand page on FB anymore to have their FB fans. However, any "liking" requires a FB account, and all the information flows back to FB. This near-monopoly in centralizing social data had led some to look for alternatives, like OpenLike and  Diaspora.  But whether those alternatives will gain wide acceptance remains to be seen, as the biggest potential rival, Google+ is still playing catch up. Some real competition in this area would be A Good Thing, by steering innovation. Let the battle for the social minds rage on.

References: Open Graph (Facebook developers site)

From Tony's Blog.
Published at DZone with permission of Tony Siciliani, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)