BLOG: Web Content Management

Welcome to Oshyn’s Web Content Management Blog where our experts discuss the latest developments and best practices in the Content Management industry with a focus on several leading platforms: Drupal, EPiServer, Jahia, Open Text and Sitecore.

Sitecore & Facebook Integration - Part I

Sitecore & Facebook Integration - Part I

Jaime Davila... - Tuesday, December 15, 2009

I'd like to talk today about a little challenge I got: Integrate Sitecore with Facebook.

Before to start working we need to download the Facebook API Toolkit for .NET, once you get the framework you need to copy the .dll files into $(iis_path)\SitecoreWebsite\Website\bin\; probably you only need to copy Facebook.dll, Facebook.Web.dll and Facebook.Web.Mvc

We need to import the WebSite project into VStudio so we can take advantage of developing within an IDE and all the features you have using VStudio, to accomplish this please follow these steps:

  • Click File->New->Import an existing project...
  • Once the project is uploaded into VStudio: Right click in References folder
  • Add Sitecore.Kernel.dll as a reference
  • To include any folder that you're not able to see, click the "view all" icon in the solution toolbar, once you see all the folders, just right click the folder you want to include and select "Include in project"

As you can see in this post you need to modify your web.config file; something that it's not said is that you need to add a reference into the VStudio project to the Facebook API Toolkit for .NET.

Now, how are we going to integrate Facebook with Sitecore?, well there are some options and we're going to focus in two of them: Facebook Connect and FBML (Running your app inside Facebook).

Because of time, I'll be using the sample data that came preinstalled into Sitecore, you can change the templates or even modify the layouts according to your site, the logic is the same, but during the excersice probably I'll make some changes to the layouts or the templates.

For a detailed description about how to integrate your app into Facebook Connect follow this link, here I'm going to give you a quick summary of the steps involved in Facebook Connect integration.

  • Create a page called xd_receiver.htm into the root
  • Put this code in the new created file
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html >
    <body>
    <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
    </body>
    </html>

  • Reference the Facebook XML Schema in the html tag
  • Reference the Facebook script library in the head tag
  • Include the login button
    <fb:login-button onlogin="window.location.reload()"></fb:login-button>
  • I'd like to think here's where the magic starts: Include this tag in every page you want to include Facebook Connect
    <script type="text/javascript">FB.init("[PASTE API KEY HERE]", "xd_receiver.htm");</script>
    If you decide to put xd_receiver.htm into a different path, here you MUST indicate the file location



Something we need to take in count: Facebook integration collisions with Sitecore in some ways, for example after you add the <script>FB.init(...)</script> you can't open the layout in the Sitecore Developer GUI becaus the cross-domain script. One possible solution is set IE to allow any connection or you, as developer, can include in the script a condition to execute the facebook call.

As you can see or test it if you decided to follow this excersice, now you have the Facebook connect which allows the user to see his name after he logged in or if he's already logged in to facebook. But we can go further and decide to incorporate some extra functionality to our site, let's say we want our visitor can see his picture.



Let's keep with this link to check how to code correctly the most fundamental parts of our code. I'm going to highlight the changes that we need to do:

  • Set the APIKey and the Secret values into AppSettings in web.config then you can call your values using ConfigurationManager.
    private string ApiKey = System.Configuration.ConfigurationManager.AppSettings["APIKey"].ToString();
    private string SecretKey = System.Configuration.ConfigurationManager.AppSettings["Secret"].ToString();
  • Please don't forget to try/catch your code because you can get a "session expired" exception.
    private void Page_Load(object sender, System.EventArgs e)
    {
    try
    {
    connectSession = new ConnectSession(ApiKey,SecretKey);
    ...
    }
    catch(Exception ex)
    {
    ... }
    }

That's it, now you can customize your site to include Facebook Connect, the next topic will be how to incorporate your sitecore app inside facebook.

ajax rotator
Recent Posts

RSS feeds
Tag cloud
thoughts online marketing web design los angeles Ubuntu Server search suggest postgis google analytics missing images design plugin Jahia foursquare keywords cluster marketing web design ajax jahia cms opentext licencing open source lead generation template design release management content management white paper LS profile tab drools Solr facebook developers wcm open text Flash jquery, jquery plugin sitecore online marketing suite, online marketing suite google appEngine IIS editing content E-commerce code design development geo social media cms los angeles JSR-168 WCM Design Patterns Navigation ipc communicating Database reddot geographical ui css sitecore meetup url tuckey VB web3.0 cloud rdbs HubSpot icefaces Active Directory social 2.0 tools Actionscript 3 Sitecore Active Directory location Business Users fbml open text delivery server linux memcache boost patterns friendly url multilingual mashups mashup mashware LDAP content management los angeles SEO cms white paper ASP.NET iphone call to action sales 2.0 theming content authors LiveServer concrete5 integration java tuning content management systems cookie-free domain drush spatial cms los angeles, content management los angeles, web development los angeles, website design los angeles, web design los angeles, sitecore meetup, sitecore user group mobile presentation layer IT Investment EPiServer Active Directory web marketing jahia wcm GSA configuration management reddot cms keyword selection portlets sitecore email campaign manager lucene content mangement webcomponent .net industry challenges campaigns modules jquery ASP.NET MVC data access Marketing Automation AS3 Ubercart Maven APC google CMS Training deployment oshyn new sites VS2010 lead management CRM open text web solutions mysql VPP content management whitepaper portal open text management server CTA enterprise php5 optimization asp liferay performance architecture Acquia search engine website design los angeles redundant database structure reddot higher education Web development open-source social network MVC reddot whitepaper templating profile box sitecore oms web development los angeles print inbound marketing sitecore user group sitecore layout facebook app, OS 3.0, three20 Drupal higher education reddot white paper management software design reddot cms higher education google search appliance web services Visual Studio command line scalability sitecore ECM cms whitepaper Sharepoint Dynamic Data CMS dynament web evolution javascript google maps web marketing for dummies ubuntu ajax push web2.0 open text cms jsp project management CMS usability Delivery Server Sitecore multisite design patterns open text liveserver twitter Visual Basic cloud computing RFP Live Server oms target dynament facebook consulting html SMM OO Development EPiServer frontend optimization content authoring sitecore devices web content management GIS php Velocity
2010 Copyright Oshyn. All rights reserved.