Facebook webforms app get app_data querystring
Asked Answered
F

2

6

How do i get app_data querystring from a Facebook webforms app? I want to be able to send some info in the querystring so i can display different home screen on my app. The app is sittin in a page tab.

Example: http://www.facebook.com/pages/APPNAME/157772164271503?sk=app_230501256972470&app_data=Page.aspx

How do i get "Page.aspx" from app_data? I need it to redirect the user to a different page from Default.aspx

I found the solution. Get Querystring from facebook tab app using asp.net

using Newtonsoft.Json.Linq;
using System.Text;

public partial class Page_Default : System.Web.UI.Page
{
    protected string output = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        output = "Whole thing:" +Request.Form["signed_request"];
        output += "Second part:" + Request.Form["signed_request"].Split('.')[1];

            try
            {
                string payload = Request.Form["signed_request"].Split('.')[1];
                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 o = JObject.Parse(json);

                output += "Decoded:" + json;

                bool liked = (bool)o.SelectToken("page.liked");

                output += "Liked:" + liked.ToString();
            }
            catch (Exception ex)
            {
                output += "Extract failed: " + ex.Message;
            }
    }
}

Also this post was helpfull

just be shure to add the direct page in facebook app settings ex. www.site.com/deafult.aspx not www.site.com

Facer answered 8/7, 2011 at 13:38 Comment(0)
K
3

In the JSON array that facebook posts, one of the top level keys is 'app_data', if it's specified. So you can to it just as you did for 'liked' but instead of 'page.liked' it would just be 'app_data' (and not a boolean)

Kwangchowan answered 27/9, 2011 at 16:2 Comment(1)
Face book make the app_data query available to all apps in page tab via the signed request. I have written a tutorial and included a PHP class that will retrieve the app data for you here -> fryed.co.uk/blog/… it also tells you how to handle retrieving multiple values from the one app data query. Hope it helps.Katrinakatrine
R
-2

facebook does not pass the querystring to your page. it does a post to your page from a different url, so you wont be able to read the querystring from page load. I havent tried this, but you could try accessing window.top.location.search in the js of the page.

Raze answered 8/7, 2011 at 14:16 Comment(4)
you can acess query strings using the method aboveFacer
From the code, and since its a POST, the app_data parameter is in the form, not the query stringAsterisk
You can't access that data from the IFrame, it has to conform to the same-domain policy.Pineapple
Its not possible to access a parent window from an I frame unless it is on the same domain. It would pose huge security risks if what you are suggesting was possible.Katrinakatrine

© 2022 - 2024 — McMap. All rights reserved.