Facebook Profile Management

In this post I will discuss how I implemented the Profile Management for Network Trotters .

Profile Management Generals

As an application developer, you get the opportunity to place some information in the user profile page. Specifically you can set a Profile Action (link below the Profile Pic) and a Profile Box.

In your application you basically tell the Facebook platform where it should get the FBML/HTML that defines both the Profile Action and Profile Box. It is important to notice, that Facebook will Cache this FBML/HTML, until you specifically tell them to refresh it.

So in summary, you set the user Profile from your application, but you have to build a mechanism to refresh the users profile periodically.

Context

I am using the Facebook Development Toolkit as the Facebook Platform API wrapper; and the profiles are set by using Urls.

.Net Implementation (one of many)

In my implementation, the profile management contains 3 main components:

  • Profile Content Page
  • Setting a user profile
  • Refresh the profile


Profile Content Page

In this component you generate the combination of FBML and HTML that will be passed to Facebook. Please note that only a subset of tags are allowed in the profile.

The following example shows part of the code I have live for Net Trotters. I set both the Action and the Profile box (the code has been re-factored for display purposes), notice that all the code below resides on the same page:

<!–Sets the Action Link –>
<fb:if-is-own-profile>
    <fb:profile-action url='<%= GuestTrotterLink %>’>
        Guest Trotters (<%= GuestTrotters %>)
    </fb:profile-action>
</fb:if-is-own-profile>
<!–Sets the Profile Box–>
<!– trotter information (to long to attach) –>
Last Updated: <%= CurrentDateTime %>

I left the Last Update  section intentionally, it is important to the user to know how old is the information he is looking at. It will be also good for the developer for debugging purposes.

Setting the Profile

Most of the applications have an specific landing page for the people that just installed the app, this will be the best place for you to set up the profile for the first time. If you don’t have a landing page, simply put it on the default page of you app.

In my appI use URLs as identifiers for the Profile content, but I believe the idea works as well with Handlers. To set the users profile you include the following code:


FBService.SetFBML(string.Format("<fb:ref url='{0}?uid={1}' />", ProfileContentUrl, FBService.UserId));

Where “ProfileContentUrl” is the url of the page you created with the code above, and the “FBService.UserId”  is the user if of the Logged In user.  Notice that for Facebook the entire URL (including the querystring) becomes a key to the cache content it generates.

At this point you have successfully set up a relationship between the Logged In user and a URL.  The profile Action Link and Box should now appear on the users profile page.

Refreshing the Profile

Now that you have set up the URL for the user, you need to update it. It is not a good idea to rely on the any single user coming back to the site, because you don’t know when that is going to happen.

My idea was to update profiles every 15 minutes, to do so, I keep the last updated time on my application’s cache, and set the expiry to 15 minutes. Every time someone goes in the application, the function gets called, if its is time to refresh the urls, it does it.When is time to refresh profiles, all you need to do is call the refresh function, which takes the Facebook Cache Key (remember, is the entire URL). The function contains the following code:

if (HttpContext.Current.Cache["UpdateProfiles"] == null)
{
List<string> userIds = dbTrotter.GetTrotterOwners();
foreach (string userId in userIds)
{
fbService.RefreshRefUrl(string.Format("{0}?uid={1}", ProfileContentUrl, userId));
}
//we set the cache
HttpContext.Current.Cache.Add("UpdateProfiles", true, null, DateTime.Now.AddMinutes(15, Cache.NoSlidingExpiration, CacheItemPriority.High, null);
}

In the code above I loop through all my users refreshing their URL, which basically indicates Facebook to clean the cache for that URL; next time the URL is requested,  it will get it from the profile handler.

That is it, you now build your Profile Content Page, you set the profile for the first time, and you updated it periodically!

References

To get more information about check out:

NOTE: Once your application gets decent numbers of users, you will need to call the function above asynchronously so the user doesn’t have to wait until the request is done. Because this post is getting a little long; I’ll do a different post about calling functions asynchronously.

Advertisements

About ricardocovo

Senior Software Architect/Developer with extensive experience in web related technologies.

4 Responses to “Facebook Profile Management”

  1. I have developed a Facebook app for the above paper which daily displays the paper’s cartoon in Facebook. It’s an IFRAME app, and each day, we upload the new cartoon to a pre-defined URL. It is then displayed in the profile using code in the default FBML box. But when we change the file, the JPG in the default FBML does not refresh and I havent succeeded in working out an easy way to do this — without changing the file name in the default FBML globally every time we upload a new cartoon. The app is at http://www.facebook.com/apps/application.php?id=4999534283
    and otherwise works fine. Have you got a suggestion? Here, every user has the same cartoon. Chris.

  2. Chris,

    Unfortunately the behavior you are referring to has more to do with browser caching than with the actual profile.

    I am note sure but you can try doing this:
    where ‘1234’ is a randomly generated number. This might trick the browser into thinking is a different file.

    Hope this helps,
    -Ricardo

  3. how do i refresh the profile box…i update a count via my app but in profile box nothing is updated…..any idea??? plz help…

    in each refresh of the app, it adds a value in DB but cant see on profile…..help help me plz..

    -sheeraz-

Trackbacks/Pingbacks

  1. C#: Asynchronical Function Calls « Ricardo Covo’s Weblog - October 11, 2007

    […] Check out my previous post for more info on Facebook Profile Management. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: