Search code examples
facebookfacebook-likefacebook-pagefacebook-wall

Facebook Fan Page "Like" Stays on Fangate page instead of moving to Wall


Desired Behavior: After using the Like button on top of my fan page, I want the user to be sent to the Wall.

Current Behavior: The user remains on the fangate page (custom tab that is set as the default landing page for my fan page).

From what I can tell from another question here, I can't control events that trigger after someone "Likes" my page if they use the button on top of the page.

However, I've been to some fan pages that DO have the behavior I want. I just can't figure out how they did it. Example: StrongMail's Facebook Fan Page

EDIT: Added information - We use an iframe for the Fangate (in case that's relevant)


Solution

  • EDIT: If you want to show certain content instead of going to the wall, make an absolute positioned div on top of your hidden content and hide the div when it's liked.

    If you're using C# ASP.Net, I've never had an issue using this technique. You can check for the signed_request and decode using JObject and then redirect as you need.

    Check this out: How to decode OAuth 2.0 for Canvas signed_request in C#?

    You'll need to download and reference JSON.Net from here: Json.NET

    On the page load:

    if (Request.Form["signed_request"] != null)
        {
            var result = (IDictionary)DecodePayload(Request.Form["signed_request"].Split('.')[1]);
    
            JObject liked = JObject.Parse(result["page"].ToString());
    
            if (liked["liked"].ToString().Trim().ToLower() == "true")
            {
               //do redirection here
            }
        }
    

    The decode payload function here:

    public Dictionary<string, string> DecodePayload(string payload)
    {
        var encoding = new UTF8Encoding();
        var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
        var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
        var json = encoding.GetString(base64JsonArray);
        var jObject = JObject.Parse(json);
    
        var parameters = new Dictionary<string, string>();
        parameters.Add("user_id", (string)jObject["user_id"] ?? "");
        parameters.Add("oauth_token", (string)jObject["oauth_token"] ?? "");
        var expires = ((long?)jObject["expires"] ?? 0);
        parameters.Add("expires", expires > 0 ? expires.ToString() : "");
        parameters.Add("profile_id", (string)jObject["profile_id"] ?? "");
        parameters.Add("page", jObject["page"].ToString() ?? "");
    
        return parameters;
    }