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;
}