Hello, I need some help with my facebook page tab. It should be pretty straight forward in terms of the amount of code needed, but I'm not 100% sure whats necessary when it comes to facebook apps/tabs instance code.
Please see below what I have currently for my app instance, in my header.php
require 'facebook-php-sdk-98f2be1/src/facebook.php';
######### edit details ##########
$appId = '000000000000000'; //Facebook App ID
$appSecret = '000000000000000000000000000000'; // Facebook App Secret
$return_url = 'http://example.co.uk/script/process.php'; //return url (url to script)
$homeurl = 'http://example.co.uk/script/'; //return to home
$fbPermissions = 'publish_stream,manage_pages'; //Required facebook permissions
$canvasPage = "http://www.facebook.com/pages/example?sk=app_000000000000000";
##################################
//Call Facebook API
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret
));
$fbuser = $facebook->getUser();
So as you can see, I started my application instance above. As you can see there is no authentication yet, as I'm not sure if it will be needed.
OK heres the idea of what I need to do...
I need to simply get to wordpress pages within the page tab from the facebook page tab url.
My current facebook page tab iframe canvas points to...
<strong>http://www.example.co.uk/</strong>
and the facebook url is... <strong>http://www.facebook.com/pages/example?sk=app_000000000000000</strong>
So I would like to be able to navigate to...
<strong>http://www.example.co.uk/on-road</strong>
via... <strong>http://www.facebook.com/pages/example?sk=app_000000000000000&app_data=on-road</strong>
<em>I'm not sure if the best way to redirect is via a script echo'd before at the top of the page like this...</em>
if ( $appData = 'on-road' ) {
echo("<script> window.open.href='" . get_bloginfo('url') . "/on-road'</script>");
}
<em>but i'm open to other suggestions.</em>
This is where I get very lost... I also need to pass a second variable though, because I am running this script below in my theme...
autoBike = function () {
var bike = '<?=(isset($_REQUEST['bike']) ? htmlentities($_REQUEST['bike']) : null)?>',
$bike = $('#bike-main-slider div.bike[data-bike=' + bike + ']');
if ( $bike.size() > 0 ) {
var bikeIndex = $bike.index();
mainSlider.goToSlide(bikeIndex);
scrollTo(378);
}
};
autoBike();
the second variable would be <strong>?bike=450cc</strong> for example.
So maybe the facebook URL would look like this...
<strong>http://www.facebook.com/pages/example?sk=app_000000000000000&app_data={"page":"on-road","bike":"450cc"}</strong>
...which would some how output this within my page tab iframe...
<strong>http://www.example.co.uk/on-road/?bike=450cc</strong>
I hope this makes sense, please feel free to ask any questions.
Full prize amount will go to working PHP addition to my current app instance.
Many Thanks
Josh
Christianto answers:
Hi Josh,
Please check this code:
[[LINK href="http://pastebin.com/28qxV2KQ"]]http://pastebin.com/28qxV2KQ[[/LINK]]
for redirect you can both javascript or http-equiv="refresh",
you can uncommented <meta> refresh if you need to use it.
edit: syntax error, please check new pastebin link..
I use facebook signed_request object in case no signed_request data pass,
so need to include facebook class
Dbranes answers:
hi, have you tried to url-encode the value of the app_data variable, to get more than one variable through?
fx:
http://www.facebook.com/pages/example?sk=app_000000000000000&app_data=on-road%26bike%3D450cc
where
app_data=on-road&bike=450cc
is written as
app_data=on-road%26bike%3D450cc
where (%26 for &) and ( %3D for =)