0

i have used get friends list from facebook using php and graph api. really stuck this issues. i have run my code localhost working but when i run my code server showing error Cannot modify header information - headers already sent by (output started at

 <?php

include 'src/facebook.php';

$app_id = "xxxxxxxxxx";

$app_secret = "xxxxxxxxx";

$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));

$user = $facebook->getUser();

if ($user <> '0' && $user <> '') { /*if valid user id i.e. neither 0 nor blank nor null*/
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me/friends');
} catch (FacebookApiException $e) { /*sometimes it shows user id even if user in not logged in and it results in Oauth exception. In this case we will set it back to 0.*/
error_log($e);
$user = '0';
}
}
if ($user <> '0' && $user <> '') { /*So now we will have a valid user id with a valid oauth access token and so the code will work fine.*/
//echo "UserId : " . $user;

$params = array( 'next' => 'http://kenshinkan.app-product.com' );
//echo "<p><a href='". $facebook->getLogoutUrl($params) . "'>Logout</a>";

$user_profile = $facebook->api('/me/friends');

echo "<p>";
//print_r($user_profile);
$json_output=($user_profile['summary']['total_count']);
echo '<p>Friends</p>'. "<h1>".$json_output. "</h1>";

} else {/*If user id isn't present just redirect it to login url*/
header("Location:{$facebook->getLoginUrl(array('req_perms' => '/me/friends,offline_access'))}");
}

?>

i have run the above code alone working well. when i include this index page its showing error?

Pixel Dev
  • 37
  • 8

0 Answers0