I have been trying to set up facebook on a page via a function that is in functions file. However I want to return multiple arrays, so I can get every bit of info.
Here’s how I’m doing it:
functions.php:
require 'src/facebook.php';
function fb_setup($app_id, $app_secret){
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
// login or logout url will be needed depending on current user state.
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
// This call will always work since we are fetching public data.
$fb = array(
"logoutUrl" => $logoutUrl,
"loginUrl" => $loginUrl
);
return $fb;
return $me;
}
test.php
require("../functions.php");
$fb = fb_setup('************','*****************************');
echo $fb['logoutUrl'];
//but I also want to get the $me info
I want to get the $me information as well.
Thanks!
This uses a multi-dimensional array although I’d recommend refactoring into a class.
e.g.