Facebook Social Connected: Where's the Data?

So I recently posted a fix for the Sitecore Social connected module to update the version of the Facebook API that was in use since the old version was no longer available. After posting this, I saw an issue mentioned on the Sitecore community site stating that the Facebook data was missing. I decided to take a look at my personal data to see - so I referred to a dated reference and checked Profile fields within the user. To my surprise, there were only a few fields and a lot of the configured fields were missing. Not having an active user base that uses the Social Connected module, I hadn't tried to look at the underlying data - but sure enough it appeared to be missing. Where's the data?

It turns out with Social Connected 3.0 that the data is stored in xDB facets, so the data isn't missing but is simply stored in a different location.

How to access those fields with Social Connected 3.0:

Get the facebook users



            var users = Domain.GetDomain("extranet").GetUsers();
            //filter for only facebook username ends with _facebook
            List facebookUserList = new List();
            foreach (Sitecore.Security.Accounts.User user in users)
            {
                string userName = user.Name;
                if (!string.IsNullOrEmpty(userName) & userName.EndsWith("_facebook"))
                {
                    facebookUserList.Add(user);
                }
            }
   

Get the facebook data


                
             foreach( Sitecore.Security.Accounts.User facebookUser in facebookUserList){
                if (facebookUser != null & facebookUser.Profile != null)
                {
                    foreach (var customPropertyName in facebookUser.Profile.GetCustomPropertyNames())
                    {
                        if (customPropertyName.Contains("fb_"))
                        {
                            string stringToLog = string.Format("Profile Field:{0}:{1}:{2}", customPropertyName, facebookUser.Profile.GetCustomProperty(customPropertyName), lineBreak);
                            Sitecore.Diagnostics.Log.Info(stringToLog, this);
                        }
                    }

                    var socialProfileManager = ExecutingContext.Current.IoC.Get();
                    SocialProfile socialProfile = socialProfileManager.GetSocialProfile(facebookUser.Name, "Facebook"); //socialProfile.Fields property should contain all fields at this moment
                    foreach (string key in socialProfile.Fields.Keys)
                    {
                        string value = socialProfile.Fields[key];
                        string stringToLog = string.Format("Social Profile Field:{0}:{1}:{2}", key, value, lineBreak);
                        Sitecore.Diagnostics.Log.Info(stringToLog, this);
                    }

                }
              }

Comments