Pass variables into Facebook iFrame app PHP

2019-03-21 22:16发布

问题:

I thought this was possible, but it doesn't seem like I can do it.

What I'm looking at doing is passing a variable into a facebook iframe application. It doesn't matter how, but I've been trying a couple different methods. If anyone has any idea.

-----edit---------

Yes (to below), I found the items if anyone else looks for this use… 

Create links...

$link_params = array(
    'item1' => "blah",
    'item2'   => "blaaaaargh"
);
$encodedParams = urlencode(json_encode( $link_params )); 
//added to link as app_data

Get data…

if (!empty($signed_request) && !empty($signed_request['app_data'])) {
  $app_data = json_decode($signed_request['app_data'], true);
} //use in your app from here as $app_data['item1']

回答1:

There is acutally something: the app_data in the signed_request. The documentation says:

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.

This means, you simply call your app, add &app_data=... to the url. Remember to encode the parameters to json first.