Archive for category Social Connected Module

Social Connected with Sitecore (Facebook) – Demo Video

Here is a demo video which I presented at work about the Social Connected Module with Sitecore.

This video speaks of all the functionalities as described in the following blog posts:
Social Connected with Sitecore (Facebook) 1: Setup & Posting messages
Social Connected with Sitecore (Facebook) 2: Access facebook information
Social Connected with Sitecore (Facebook) 3: Post ad hoc messages to facebook
Social Connected with Sitecore (Facebook) 4: Disconnect profile

The presentation used in this demo:

Download Presentation

, , , ,

Leave a comment

Sitecore Social Connected – String was not recognized as a valid DateTime

There is an issue we stumbled upon using Sitecore 7.0 and Social Connected Module 2.0.
The following config entry in ~\App_Config\Include\Sitecore.Social.config is used, as mentioned to update the user data from facebook on each login.

      <!-- Is Profile updating at user login functionality enabled. -->
      <setting name="Social.ProfileUpdating.EnableProfileUpdating" value="true" />

Once this property is switched to true, and you have a facebook login created in your system, you start to get the following issue when you try to access sitecore:
2014-06-30_015505

Toggling this property off resolved this issue, and as a work around, for this version we would need to do the following:

  • <setting name=”Social.ProfileUpdating.EnableProfileUpdating” value=”true” /> – For content delivery (CD) environments only
  • <setting name=”Social.ProfileUpdating.EnableProfileUpdating” value=”false” /> – for content management (CM) environment(s) only

, , ,

Leave a comment

Disabling the Attachment of a Visitor’s Social Network Accounts to their Sitecore User Profile

Once your site is configured to enable login using Social Media website logins, when a user logs in for the first time to the site using social media website credentials, one of the following scenarios kick in:

  • The email id does not exist in the corresponding core database, and a new user is created corresponding to this new email id.
  • The email id already exists in the core DB (User Manager) and the social media profile is merely attached to this existing record.

This is the default behavior of the social connected module.
However, depending on the business needs of your site, you might want to override this behavior and provide the ability for a user to have separate logins (site created login and social media credential login).

To override this functionality, we need to override the FacebookLoginButtonOneClick() method which is executed in the ‘~\layouts\system\Social\Connector\Login with Facebook.ascx’ (Sitecore.Social.Facebook.Client.dll – Class:Sitecore.Social.Facebook.Client.Connector.Controls.LoginWithFacebook)
2014-06-30_005944

        protected void FacebookLoginButtonOneClick(object sender, ImageClickEventArgs e)
        {
            const bool updateSocialProfileAsync = true; 
            var connectorClientManager = new ConnectorClientManager();
            if (!Sitecore.Context.User.IsAuthenticated)
            {
                connectorClientManager.LogOnUser("Facebook", new ApplicationCredentials
                {
                    ApplicationKey = "<your app key>", 
                    ApplicationSecret = "<your app secret>"
                },
                updateSocialProfileAsync);
            }
            else
            {
                connectorClientManager.AttachToUser("Facebook", new ApplicationCredentials
                {
                    ApplicationKey = "<your app key>",
                    ApplicationSecret = "<your app secret>"
                }, 
                updateSocialProfileAsync);
            }
        }

, , ,

Leave a comment

Social Connected with Sitecore (Facebook) 4: Disconnect profile

Disconnecting a facebok profile from sitecore can entail 2 activities:

  • Revoke permission granted to your application in the user facebook profile
  • Delete the facebook user information from the Sitecore Core database
  • If the user was created from the facebook login, log out the user and then delete the user from sitecore

Revoke permission granted to your application in the user facebook profile
Here we will be using the facebook js API to deauthorize our application

<script type="text/javascript">
    function fbDeauth() {
        FB.api('/' + '<%= Sitecore.Context.User.Profile.GetCustomProperty("fb_id")%>' + '/permissions', 'DELETE', function (res) {
            if (res === true) {
                alert('app deauthorized');
            } else if (res.error) {
                alert("res.error" + res.error.type + ': ' + res.error.message);
            } else {
                alert("Else:" + res);
            }
        });
        return false;
    }
</script>

Delete the facebook user information from the Sitecore Core database
You could loop through all the relevant (prefix ‘fb_’) user properties and delete them:

foreach (var customPropertyName in Sitecore.Context.User.Profile.GetCustomPropertyNames())
{
    if (customPropertyName.Contains("fb_"))
        Sitecore.Context.User.Profile.RemoveCustomProperty(customPropertyName)
}

If the user was created from the facebook login, log out the user and then delete the user from sitecore
If the user was created using a facebook login, the username will be suffixed with ‘_facebook’.
2014-06-30_004340
Based on this, you could log out the user and delete the profile.

, , ,

1 Comment

Social Connected with Sitecore (Facebook) 3: Post ad hoc messages to facebook

The facebook social connected module only allows your application to post to a user timeline when a goal is triggered.

Your site business logic might need you to make ad hoc posts when certain logic is triggered. While we could definitely achieve the results we want by creating goals for each of these actions, this might not adhere with the marketing guidelines.

So here is how we achieved this functionality using the Facebook js API

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
var facebookAppId = '<%=FacebookDefaultAppId %>';
FB.init({ appId: facebookAppId, status: true, cookie: true, xfbml: true });

function openFbPopUp() {
FB.ui({
method: 'feed',
name: 'Your Site Name',
caption: ' ',
link: document.URL, // Current Url
description: $('#quotes').html(), 
// Description from the sitecore item which was available in the same page
display: 'popup'
});
return false;
}
</script>

FacebookDefaultAppId – was the app id (Application Id) set in the sitecore item where we set the facebook app details:

1hvuP

Which we get here in facebook for the app created:
7Jbdw

Truth be told, this solution has nothing to do with sitecore, but since we manage the app secret key in sitecore, I am pulling it in from there as opposed to saving it some place else too.

This results in the following when the js is triggered (say on button click):
2014-06-17_194018

, , ,

1 Comment

Social Connected with Sitecore (Facebook) 2: Access facebook information

In an earlier post, we went over the setup of the Social Connected Module with Sitecore.
You can control the fields that you would want to access through the ~\App_Config\Include\Sitecore.Social.ProfileMapping.Facebook.config file.

Once a user logs into your site using their facebook login, based on your configuration settings, this data will be pulled into the core database against this user record.
However, this data is not by default visible through the user manager console of sitecore.

You can however, access this data via code and then choose to show it in user manager properties.
Take a look at Creating an extended Sitecore user for your site to create custom user properties.

Following is the code which would enable you to access the facebook data:

                foreach (var customPropertyName in Sitecore.Context.User.Profile.GetCustomPropertyNames())
                {
                    if (customPropertyName.Contains("fb_"))
                    {
                        litFacebookData.Text += customPropertyName + ": " + Sitecore.Context.User.Profile.GetCustomProperty(customPropertyName) + "<br>";
                    }
                }

The fields available in the ~\App_Config\Include\Sitecore.Social.ProfileMapping.Facebook.config don’t seem to provide a way to fetch the user profile picture from facebook!
So when the requirement came up, we ended up using the Graph API facebook provides, which takes as input the facebook user id. This is available in the core database with property name ‘fb_id’.

var facebookPictureUrl = "http://graph.facebook.com/{0}/picture?type=normal";
imgFacebookPicture.ImageUrl = string.Format(facebookPictureUrl, Sitecore.Context.User.Profile.GetCustomProperty("fb_id"));

Here is the result of the above code, as you see, the facebook data pulled in has property names prefixed by ‘fb_’. Also note the profile picture (QR Code).
2014-06-29_210334

Following is a user created using a facebook login.
Please note, when a user is created using facebook, an ‘_facebook’ is appended to the name. The user name however, doesn’t change if an existing user (same email id as facebook login) attaches his user id to his facebook profile.

2014-06-30_004340

, , ,

1 Comment

Social Connected with Sitecore (Facebook) 1: Setup & Posting messages

Almost all up to date web facing sites today call for the need of being integrated with the social media websites. Sitecore has this handy Sitecore connected module which helps us deal with this needed integration to an extend. In this post, I am going to briefly go over some of the features that the social connected module comes with and steps to set this up.
Please note, this is on Sitecore 7.0 and Social Connected 2.0.
I will only be going over facebook but do note that Sitecore Social connected does support LinkedIn, Twitter and Google+ as well.

The Social Connected module will enable you to do the following through configurations alone:

  • Allow users to login to your site using configured social media websites by only adding the relevant user control to your page. Using the relevant config file settings, you can also determine what user data you will want to store in your databases from Facebook, when a user uses their facebook login to log into your site.
  • Publish facebook messages to a user (using facebook to log into your site) timeline when the user triggers a dms goal on the site
  • Post to a facebook timeline to a preconfigured company / website owned official facebook account timeline, when an item is published.
  • Allow you to place like / share buttons on your site pages again by adding only the relevant user control.

To be able to allow users to log into your website using facebook, you will need to create a Facebook app.

Creating a facebook app:

  1. In https://developers.facebook.com/, create a new app
    2014-06-29_002903
  2. Fill in the required information. Please note, an email address is required for a public app (which you need to enable connectivity from your site). You will also need to add a platform – In this case, a website and set the url.
    2014-06-29_003720
    Here is the sample:
    2014-06-29_003702
  3. You will need to make the app public:
    2014-06-29_003959
    Please note, that only the above fields in green – email, public_profile, user_friends are allowed to be accessed by default. Accessing any additional fields will require access from Facebook. This can be requested using the Review Submission Form, available in the Status & Review tab:
    2014-06-29_004346

Now that the Facebook setup is done, we can go ahead and get our sitecore instance set up.
You might want to look at the Modules Compatibility Table to ensure you have a compatible version of the module for your version of sitecore. The Known Issues are also listed here.

Sitecore Setup:

Once you have installed the Social Connected module, create a default application in the following location:
2014-06-29_104647

The ApplicationId and ApplicationSecret will be available in your facebook app.

That’s it! You are all set!
You’ll need to add the login sublayout onto your page:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FacebookLoginRedirect.ascx.cs" Inherits="Sitecore7.layouts.SocialDemo.FacebookLoginRedirect" %>
<%@ Register Src="~/layouts/system/Social/Connector/Login with Facebook.ascx" TagPrefix="uc1" TagName="LoginwithFacebook" %>

<uc1:LoginwithFacebook runat="server" ID="LoginwithFacebook" />

2014-06-29_105121

When you attempt login, if you see an error:
2014-06-29_105812
You need to check your facebook app settings and make sure that the app domain matches the site Url and the Url you are using currently to hit facebook.
2014-06-29_110000

Once a user logs in using facebook, the same page which the sublayout resides on, refreshes after log in. If you would want it to redirect, you could use the following:

private void Page_Load(object sender, EventArgs e)
        {
            string fbId;
            if (Request.QueryString["authResult"] != null && IsFacebookLogin(out fbId))
            {
                var facebookDataItem = Sitecore.Context.Database.GetItem("/sitecore/content/Home/FacebookData");
                Response.Redirect(facebookDataItem.Paths.Path.Replace(facebookDataItem.Paths.ParentPath, ""));
            }
        }

public bool IsFacebookLogin(out string fbId)
        {
            fbId = string.Empty;
            if (!Sitecore.Context.User.IsAuthenticated) return false;

            fbId = Sitecore.Context.User.Profile.GetCustomProperty("fb_id");
            return !string.IsNullOrEmpty(fbId);
        }

You could similarly also use the Like sublayout on your page:

<%@ Register Src="~/layouts/system/Social/Sharing/LikeButton.ascx" TagPrefix="uc1" TagName="LikeButton" %>
<uc1:LikeButton runat="server" ID="LikeButton" />

Note on configurations for the Social Connected Module

Following are where all the related configs reside:

  • ~\App_Config\Include\Sitecore.Social.config:
    • Social.ProfileUpdating.EnableProfileUpdating – enable user profile information from facebook on login
  • ~\App_Config\Include\Sitecore.Social.Facebook.config
    • Social.Facebook.HasWriteAccess – This needs to be set to true if you want to be able to post to a users timeline.
  • ~\App_Config\Include\Sitecore.Social.ProfileMapping.Facebook.config – Here is where you would select the fields / user data that your application would want to access from facebook. When a new user tries to log into your site through facebook, they will be prompted to grant access to the fields which are set to true in this config file.

Posting messages to user timeline when a goal is triggered

Assuming you have a goal created already, all you need to do is configure a message which will be posted when this goal is triggered.

This can be done using the ‘Messages’ command in the Publish ribbon of the goal:

2014-06-29_122605

2014-06-29_122735

Publish messages to a preconfigured company / website owned official facebook account timeline, on item publish

You might want to push updates for newly published items automatically onto the official facebook feed. For this you need to create an account in sitecore providing the official facebook login credentials (You would want to post on this timeline)

For this, you need to add an account in sitecore:

2014-06-29_143348

You will then be asked for facebook crendentials and the account is now created.
We now need to add the message to be published to the corresponding item. This can again be done using the ‘Messages’ command in the Publish ribbon.

You also need to select the account you created here.

2014-06-29_150428

Once this is done, you could either manually post this message or have it post automatically on item publish (by checking the corresponding checkbox)

2014-06-29_150618

All set!

2014-06-29_150955

Message posted on facebook! 🙂

2014-06-29_151112

Thanks to Dan Solovay’s blog which helped me get through this initial setup and inbuilt functionality. More social media related sitecore posts coming up next!

, , , ,

6 Comments