Understanding the Open Graph Protocol 54

Một phần của tài liệu Mining the social web, 2nd edition (Trang 80 - 85)

Part I. A Guided Tour of the Social Web Prelude

2. Mining Facebook: Analyzing Fan Pages, Examining Friendships, and More

2.2. Exploring Facebook’s Social Graph API 46

2.2.2. Understanding the Open Graph Protocol 54

In addition to sporting a powerful Graph API that allows you to traverse the Social Graph and query familiar Facebook objects, you should also know that Facebook un‐

veiled something called the Open Graph protocol (OGP) back in April 2010, at the same F8 conference at which it introduced the Social Graph. In short, OGP is a mechanism that enables developers to make any web page an object in Facebook’s Social Graph by 54 | Chapter 2: Mining Facebook: Analyzing Fan Pages, Examining Friendships, and More

2. Throughout this section describing the implementation of OGP, the term Social Graph is generically used to refer to both the Social Graph and Open Graph, unless explicitly emphasized otherwise.

injecting some RDFa metadata into the page. Thus, in addition to being able to access from within Facebook’s “walled garden” the dozens of objects that are described in the Graph API Reference (users, pictures, videos, checkins, links, status messages, etc.), you might also encounter pages from the Web that represent meaningful concepts that have been grafted into the Social Graph. In other words, OGP is a means of “opening up” the Social Graph, and you’ll see these concepts described in Facebook’s developer docu‐

mentation as its “Open Graph.”2

There are practically limitless options for leveraging OGP to graft web pages into the Social Graph in valuable ways, and the chances are good that you’ve already encountered many of them and not even realized it. For example, consider Figure 2-5, which illus‐

trates a page for the movie The Rock from IMDb.com. In the sidebar to the right, you see a rather familiar-looking Like button with the message “19,319 people like this. Be the first of your friends.” IMDb enables this functionality by implementing OGP for each of its URLs that correspond to objects that would be relevant for inclusion in the Social Graph. With the right RDFa metadata in the page, Facebook is then able to un‐

ambiguously enable connections to these objects and incorporate them into activity streams and other key elements of the Facebook user experience.

Figure 2-5. An IMDb page featuring an implementation of OGP for The Rock

Implementation of OGP manifesting as Like buttons on web pages may seem a bit obvious if you’ve gotten used to seeing them over the past few years, but the fact that Facebook has been fairly successful at opening up its development platform in a way

2.2. Exploring Facebook’s Social Graph API | 55

that allows for arbitrary inclusion of objects on the Web is rather profound and has some potentially significant consequences.

For example, at the time of this writing in early 2013, Facebook has just started the process of launching its new Graph Search product to a limited audience. Whereas companies like Google crawl and index the entire Web in order to enable search, the basic idea behind Facebook’s Graph Search is that you type something into a search box, just like in the typical Google user experience, but you get back results that are person‐

alized to you based upon the vast amount of your information that Facebook has. The rub, now that OGP is fairly well established, is that Facebook’s Graph Search results won’t be limited to things within the Facebook user experience, since connections from the Web are inherently incorporated into the Social Graph. It’s out of scope to ponder the wider ramifications of how disruptive Graph Search could be to the Web given Facebook’s user base, but it’s a thought exercise well worth your time.

Let’s briefly take a look at the gist of implementing OGP before moving on to Graph API queries. The canonical example from the OGP documentation that demonstrates how to turn IMDb’s page on The Rock into an object in the Open Graph protocol as part of an XHTML document that uses namespaces looks something like this:

<html xmlns:og="http://ogp.me/ns#">

<head>

<title>The Rock (1996)</title>

<meta property="og:title" content="The Rock" />

<meta property="og:type" content="movie" />

<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />

<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />

...

</head>

...

</html>

These bits of metadata have great potential once realized at a massive scale, because they enable a URI like http://www.imdb.com/title/tt0117500 to unambiguously represent any web page—whether it’s for a person, company, product, etc.—in a machine-readable way and further the vision for a semantic web. In addition to being able to “like” The Rock, users could potentially interact with this object in other ways through custom actions. For example, users might be able to indicate that they have watched The Rock, since it is a movie. OGP allows for a wide and flexible set of actions between users and objects as part of the Social Graph.

If you haven’t already, go ahead and view the source HTML for http://

www.imdb.com/title/tt0117500 and see for yourself what the RDFa looks like out in the wild.

56 | Chapter 2: Mining Facebook: Analyzing Fan Pages, Examining Friendships, and More

At its core, querying the Graph API for Open Graph objects is incredibly simple: append a web page URL or an object’s ID to http(s)://graph.facebook.com/ to fetch details about the object. For example, fetching the URL http://graph.facebook.com/http://

www.imdb.com/title/tt0117500 in your web browser would return this response:

{

"id": "114324145263104", "name": "The Rock (1996)",

"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs344.snc4/...jpg", "link": "http://www.imdb.com/title/tt0117500/",

"category": "Movie",

"description": "Directed by Michael Bay. With Sean Connery, ...", "likes" : 3

}

If you inspect the source for the URL http://www.imdb.com/title/tt0117500, you’ll find that fields in the response correspond to the data in the meta tags of the page, and this is no coincidence. The delivery of rich metadata in response to a simple query is the whole idea behind the way OGP is designed to work. Where it gets more interesting is when you explicitly request additional metadata for an object in the page by appending the query string parameter metadata=1 to the request. Here is a sample response for the query https://graph.facebook.com/114324145263104?metadata=1 in which we use its ID instead of the IMDB web page URL:

{

"id": "114324145263104", "name": "The Rock (1996)",

"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/..._s.jpg", "link": "http://www.imdb.com/title/tt0117500",

"category": "Movie",

"website": "http://www.imdb.com/title/tt0117500",

"description": "Directed by Michael Bay. With Sean Connery, ...", "about": "Directed by Michael Bay. With Sean Connery, Nicolas Cage, ...", "likes": 8606,

"were_here_count": 0, "talking_about_count": 0, "is_published": true, "app_id": 115109575169727, "metadata": {

"connections": {

"feed": "http://graph.facebook.com/http://www.imdb.com/title/...", "posts": "http://graph.facebook.com/http://www.imdb.com/title/...", "tagged": "http://graph.facebook.com/http://www.imdb.com/title/...", "statuses": "http://graph.facebook.com/http://www.imdb.com/title/...", "links": "http://graph.facebook.com/http://www.imdb.com/title/...", "notes": "http://graph.facebook.com/http://www.imdb.com/title/...", "photos": "http://graph.facebook.com/http://www.imdb.com/title/...", "albums": "http://graph.facebook.com/http://www.imdb.com/title/...", "events": "http://graph.facebook.com/http://www.imdb.com/title/...", "videos": "http://graph.facebook.com/http://www.imdb.com/title/...", },

2.2. Exploring Facebook’s Social Graph API | 57

"fields": [ {

"name": "id",

"description": "The Page's ID. Publicly available. A JSON string."

}, {

"name": "name",

"description": "The Page's name. Publicly available. A JSON string."

}, {

"name": "category",

"description": "The Page's category. Publicly available. ..."

}, {

"name": "likes",

"description": "\\* The number of users who like the Page..."

}, ...

] },

"type": "page"

}

The items in metadata.connections are pointers to other nodes in the graph that you can crawl to get to other intriguing bits of data. For example, you could follow the

“photos” link to pull down photos associated with the movie, and potentially walk links associated with the photos to discover who posted them or see comments that might have been made about them. In case it hasn’t already occurred to you, you are also an object in the graph. Try visiting the same URL prefix, but substitute in your own Face‐

book ID or username as the URL context and see for yourself (e.g., visit https://

graph.facebook.com/<YOUR_FB_ID> in your web browser).

Try using the Facebook ID “MiningTheSocialWeb” to retrieve details about the official Facebook fan page for this book with the Graph API Explorer. You could also modify Example 2-1 to programmatically query for https://graph.facebook.com/MiningTheSocialWeb to re‐

trieve basic page information, including content posted to the page.

For example, appending a query string with a qualifier such as "?

fields=posts" to that URL would return a listing of its posted content.

As a final note of advice before moving on to programmatically accessing the Graph API, when considering the possibilities with OGP be forward-thinking and creative, but bear in mind that it’s still evolving. As it relates to the semantic web and web stand‐

ards in general, the use of “open” has understandably generated some consternation.

Various kinks in the spec have been worked out along the way, and some are still 58 | Chapter 2: Mining Facebook: Analyzing Fan Pages, Examining Friendships, and More

probably being worked out. You could also make the case that OGP is essentially a single- vendor effort, and it’s little more than on par with the capabilities of meta elements from the much earlier days of the Web, although the social effects appear to be driving a very different outcome.

Whether OGP and Graph Search will one day dominate the Web is a highly contentious topic, the potential is certainly there; the indicators for its success are trending in a positive direction, and many exciting things may happen as the future unfolds and innovation continues to take place. Let’s now turn back and hone in on how to access the Graph API to work now that you have an appreciation for the fuller context of the Social Graph.

Một phần của tài liệu Mining the social web, 2nd edition (Trang 80 - 85)

Tải bản đầy đủ (PDF)

(448 trang)