user975044
user975044

Reputation: 385

Facebook app_data

Can someone explain to me how to use facebook app_data which is part of the signed request?

http://developers.facebook.com/docs/authentication/signed_request/

The documentation is vague. I can't figure out how to actually use the app_data field. I want to be able to pass the app data to the app when it is added to a page so that the content displayed on it is relevant to the Facebook page.

for example I want a user profile on my site to only be displayed on that users facebook page. To do so I want to send the user ID to the fb signed request when the user adds the app to their page. Then anytime the page is visited I will pull the app data and run some php to display the correct profile.

Can I do this with the app_data or is this not possible?

Upvotes: 11

Views: 8193

Answers (1)

bool.dev
bool.dev

Reputation: 17478

From the documentation that you have cited

App Data is

A JSON string containing the content of a query string parameter also called app_data. Usually specified when the application built the link to pass some data to itself. Only available if your app is an iframe loaded in a Page tab.

So app data is useful only when your application has generated a link that some user will click and follow through to your app on some Facebook page.

And if a user is visiting some page (and the app tab) directly, then you won't get the app_data field.

Once a user has installed your app (and has given your app minimum permissions) on any one of their pages, you always have the page_id and user_id fields in the signed_request that Facebook will send to your app, both in canvas apps (no page_id field) and page tab apps.

For what you want to do, you can just read the signed_request and then find out the page_id and display data accordingly, you do not even have to use user_id.

Hope this answers your question. Do ask for clarifications, if required.

Upvotes: 10

Related Questions