I'm trying to pass a single variable to a Facebook Page Application. The dialog url looks like follows:
$data = json_encode('{"pid":"'.$places_id.'"}');
https://www.facebook.com/dialog/pagetab?app_id=APP_ID&app_data=".$data."&next=REDIRECT_URI
The installation of the app works fine, but the signed request parameter just does not contain the app_data field.
On the Facebook Page Tab, I use PHP to retrieve the signed request data:
require 'facebook.php';
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
When I print the signed request array on my Facebook Page Tab, I just get the following
Array (
[algorithm] => HMAC-SHA256
[issued_at] => 1372693029
[page] => Array ( [id] => ID [liked] => [admin] => 1 )
[user] => Array ( [country] => de [locale] => en_US [age] => Array ( [min] => 21 ) ) )
Any ideas?
The problem is that the dialog page does not use the app_data parameter. You need to redirect back to the app with that parameter and data in the address. So, you need to change the REDIRECT_URI to a specific Facebook app URL with that custom GET value.
EDIT
The getLoginUrl()
method from the Facebook API helps to simplify things. Notice the area that defines the app_data array in the return URI.
$canvas = "http://www.facebook.com/{PAGE_NAME}/app_{APP_ID}";
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'display' => 'page',
'req_perms' => '',
'next' => $canvas."?app_data[]=share",
'cancel_url' => $canvas
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.