coder
coder

Reputation: 1941

Passing custom parameters to facebook page tab

I have a facebook app which I want to install on multiple pages. I'm currently using the graph API /<page_id>/tabs to POST app on a page. I want some custom parameters to be passed to the app depending on which page the app is installed on. For this, I saw few docs where facebook page tab can have urls like facebook.com/<page_id>/?id=<page_id>&sk_app=<app_id>&app_data=<app_data>. But how to add this app_data while posting apps to a page? I tried passing a parameter app_data as part of POST data to /<page_id>/tabs API. But the tab url still doesn't have the app_data.

Upvotes: 0

Views: 1755

Answers (1)

madebydavid
madebydavid

Reputation: 6517

The app_data parameter is for when you create links to an app on a page and you want to include some extra info - for example, if you have an app where people draw pictures and then share them with their friends, you can give people a Share button which includes a link to the app on the page with the app_data parameter set to their drawing_id so that your app loads up their picture when their friends click on the link. It's not really intended for what you want; it will always be empty when someone goes straight to your app on a page.

It sounds like you just need to detect which page your app is currently being displayed on and perform some logic based on that.

The page data is provided to your app via the signed_request variable which Facebook POSTs to the server when the app is requested. The docs for signed_request are here. You will need to decode the signed request using your app secret. You can find the code to do that in PHP here (sorry, you didn't specify which language you are developing in).

The signed_request is a JSON object which looks similar tothis:

{
     "algorithm":"HMAC-SHA256",
     "issued_at":1389362066,
     "page":{
         "id":"189223131098036",
         "liked":false,
         "admin":true
    },
    "user":{
        "country":"gb",
        "locale":"en_GB",
        "age":{
            "min":21
        }
    }
}

To determine which page the app is shown on you just need to look at the id returned in the page part of the JSON.

Upvotes: 4

Related Questions