Connect/Providing Social Context
From Facebook Developer Wiki
Contents |
Benefits
Facebook has always had a goal to make the world a more open and connected place. Traditionally, transparency and openness on the Web have been defined by the amount of content that is easily and readily available to anyone that wants to consume it.
In a social environment that openness is defined a little differently though. When consumers are the ones controlling that content, that openness is defined by how open a platform is to enabling those people to share that content specifically to those they want to share it with.
Facebook is pioneering this new method of openness and transparency by opening up the Social Graph, and in turn, providing the tools necessary to allow users in that Graph to share that content with only the individuals they want to share it with. Facebook is "giving people the power to share in order to make the world more open and connected". (Mark Zuckerberg - http://www.facebook.com/video/video.php?v=28083185043)
Virtuous Cycle of Sharing
In 2008, at Facebook's annual F8 event, CEO Mark Zuckerberg talked about a "Virtuous Cycle of Sharing", in which he explained how Facebook, by nature, encourages sharing amongst users. This sharing results in a continuous cycle of people sharing with each other. "Feeds surface recent content, which drives consumption of recent content, which drives production of more recent content, which is [then] surfaced in the feed."
Facebook itself has seen the benefits of tracking the activity of its users and sharing that activity with their friends via the News Feed. When they see what their friends are doing, they comment on or like those items. When they comment on or like those items, they want to share more information, and the cycle continues.
Facebook, since opening up this sharing of activity via the News Feed, has seen significant growth itself. Just recently Facebook hit the landmark of over 300 million users because of this cycle of sharing. Facebook has also seen significant increase in activity through the site, and overall more connections amongst friends, family, and co-workers.
Featuring Recent Activity through Your Experience
Through the power of Facebook Connect on your own site, you can track and share the activity of your own users that are on Facebook, and see similar results.
More Activity
By tracking what your users are doing and enabling them to interact with each other, you'll see more activity on your site. As they interact with your site, their friends will see their activity, and their friends will respond, and interact as well, prompting more friends to interact and share.
Facebook provides you with all the tools to make this process easy, enabling the same Virtuous Cycle of Sharing that occurs on Facebook to happen on your own site as well. As usual with Facebook Connect, this happens with little effort on your part at all!
More Page Views
It's hard not to mention the boost in page views you'll see as a result of the increased activity on your site. When you enable your users to share via Facebook Connect, they spend more time on your site. For example:
- Imagine you are sharing the articles your users are commenting on. When their friends see these comments in their stream they are more likely to click through and read those articles. As friends of the individual who commented, they too feel part of that conversation and will want to participate as well.
- Or, what if you sell tickets to events? You could share the events a user's friends just bought tickets to. When these friends see this, they too are more likely to look at the event and purchase tickets as well.
- Suppose you enable users to share their photos or videos. Sharing those photos in your users' streams can be a great conversation starter. When they see their friends' photos and videos they are likely to click on the photos and comment, bringing more page views to each photo they comment on.
Facebook has opened up their Social Graph to give websites and businesses more power to share. It's now up to you to utilize that Social Graph, using Facebook Connect, to further empower those users to share as they please within your own product or service.
How It Works
Automatically Showing Your Facebook Friends and Their Activity
The first thing your users should see when they log in through Facebook is a stream of the activity of all their friends through your site. This can be anything from comments they make on your site, to game scores, to articles they publish, photos or videos they upload, or things they purchase through your site. Hopefully you are tracking this somewhere, or, if you're publishing your users' activities on your site to Facebook you can also pull that activity straight from Facebook with little effort on your part.
The best way to see this in action is to look how other sites are doing it. Here are some great examples:
Case Study: HuffingtonPost.com
HuffingtonPost.com recently integrated Facebook Connect into their user experience in a unique way which helps users share news better. The integration runs deep, enabling users to let their friends know, in an activity stream, what they are reading and liking as they read it on HuffingtonPost.com. After a user logs in through Facebook Connect for the first time on HuffingtonPost.com they are immediately presented with a stream of activity of what their friends are reading and commenting on, encouraging each other to participate further. Here's how it works:
- Users log in through Facebook on HuffingtonPost.com.
- They set various preferences enabling them to choose how they share their data. Note that defaults are set as checked where any Facebook automation could occur (like the auto-importing of new friends as they join the site, or automatically sharing articles a user has read or commented on with their friends).
- HuffingtonPost reads the user's other Facebook friends using the site, and displays all their activity in a stream for the user to view and discover new news.
- As each reader reads new articles or comments and participates on the site, HuffingtonPost automatically stores that activity and shares that in their friends' streams as well.
HuffingtonPost readers can click on individuals and read their activity streams, or look across all their friends cumulatively as they read and share items.
Being able to read a user's list of Facebook friends and tie that into real data on the Huffington Post enables the HuffingtonPost.com to provide more relevant articles, and keep readers on the site longer. It also helps spread the word about their website to others.
Case Study: Facebook Photos
Facebook's own Photos app lives up to Facebook's standard of sharing friend activity. If you visit the app you'll notice that immediately a list of your friends' most recent albums appear and you're encouraged to check them out, click on them, comment on them, tag other friends, and more. Implementation of this is simple:
- Track when the photos were uploaded.
- Track who uploaded them (on your own site; hopefully these users are tied to Facebook IDs).
- Now, users can do things with those photos like comment on them or share them with more friends on Facebook.
- The natural flow of visiting an app and seeing the recent photos of your friends like this encourages users to engage their friends by uploading more photos, increases comments, and in the end increases page views and potential sales for you and your brand.
Implementation: Providing Context by Retrieving Activity of a User's Friends
Facebook provides the friends and social graph for each of your users that have Facebook accounts. Through Facebook Connect you now have a means to authenticate, register, and use existing connections straight from Facebook, all right in your own environment. It's now your responsibility to start tracking the activity of these users so you can share that with their friends. You can do so one of two ways:
Option 1: Tracking User Activity
As your users are interacting with your site, you'll want to track their activities in your database. Things like the date they upload photos, when they comment, who they're commenting with, etc.
Then, to retrieve that data you'll want to get the list of their Facebook friends that are on your website. You can do so by either calling the friends.getAppUsers API call, or, even better, make an FQL query using the friend and user tables, like this:
Once you get the list of Facebook friends you can match each of them to your database and retrieve the activities you want to share with the user, displaying them automatically after the user has logged in.
Now you can give those users stuff to do with each of those activities -- read more in the Sharing Users' Recent Activity with Facebook article.
Option 2: Getting Data from the Stream
If you are sharing your users' activity straight to their Facebook stream, you can dive into the stream to retrieve the activities a user's friends have participated in on your site. Here's how you do that.
First, you want to get the list of the user's friends using your website on Facebook, as we mentioned above in Option 1.
Then, for each of those friends you'll want to retrieve the data for your site from their stream. You can get it all using fql.multiquery, and a couple FQL queries that pull each friend's activity and related comments for your site. You'll want to start by getting your application's filter key - you'll use this to retrieve only the posts in a user's stream that your website has generated. The FQL for this will look something like this:
You can actually embed that into a subquery that gets the filter key, and all the posts for that application in the user's stream in one call - it will look something like this (you'll want to adjust it to retrieve the columns you need from Facebook - you can see what's available in the stream FQL table:
Now, you'll want to get a list of all the comments for each post. You can do this one of two ways: On a post-by-post basis with a FQL query like this:
Or you can combine your first query with this one, and use the fql.multiquery API call to pull all the data at once. This saves you bandwidth and reduces the time it takes to retrieve the data:
Then, when you send fql.multiquery it would look something like this in PHP:
Doing this for each friend, you can then use the resulting data to parse out their activities, and display them to the user in a well-formatted stream adjusted for your website.
Best Practices
Keep these best practices in mind as you consider how you want to share your users' recent activity with Facebook.
Sharing Relevant Activity of Users Based on Your Brand
It's important that, while displaying the activity of a user's friends to each user is good to do, the data you share must be relevant to each user's experience on your site. For instance, if you have a photos section in your site, you may want to focus on only sharing the activities and comments centered around sharing photos in that area. Or, if your site focuses around events like concerts or movies, you may want to just focus on recent ticket purchases by each user's friends. The more targeted you can be, the more likely users will engage their friends and the more likely they will convert to sales due to the increased engagement.
Using FQL vs. API
Generally, if you have to make multiple queries in a short span, you should use FQL to retrieve that data. Another case for FQL is if you have to retrieve several columns of data at once. However, if you just want to retrieve one or two columns of data, it might be easier to just retrieve that data from the API.
Prompting for Permission
If you are retrieving data from a user's stream, they'll need to give you read_stream extended permission. You can do so via either the fb:prompt-permission XFBML tag (initiated by the user clicking a link), or by calling FB.Connect.showPermissionDialog in your JavaScript (initiated when you call the JavaScript). You can do this at any time throughout your website as needed. It may be best to just call this when the user connects for the first time so they're ready to start receiving their stream.
