Reputation:
I am trying to retrieve information through Facebook graph api, using the below code which is returning me nothing, I wrote this code after getting help from on line documentations etc. but it's not working.
Kindly help me with this.
include ('src/facebook.php');
$app_id = "160336957418730";
$app_secret = "************************";
$facebook = new Facebook( array('appId' => $app_id, 'secret' => $app_secret, ));
$user = $facebook -> getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook -> api('/me');
//$user_profile = $facebook->api('/me/home');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
echo $user_profile[name];
echo $user_profile[id];
echo $user_profile[picture];
I treid them all but nothing is working.
Upvotes: 1
Views: 338
Reputation: 4150
you need to echo from the user_profile array. Try like below $user_profile[name]; its weird with no quotes to string from but that is how we access the arrays.
include ('src/facebook.php');
$app_id = "160336957418730";
$app_secret = "************************";
$facebook = new Facebook( array('appId' => $app_id, 'secret' => $app_secret, ));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
//$user_profile = $facebook->api('/me/home');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
echo $user_profile[name];
echo $user_profile[id];
echo $user_profile[picture];
Upvotes: 1