Reputation: 3160
every time i get 0 after getting permission from Facebook.where do i wrong ? and what is getAccessToken() ??
i had a working script but i lost it, anyone have a working script ?
This is my code:
<?PHP include_once "src/facebook.php"; $app_id = "525085840939034"; $app_secret = "80b8a0095f0af94c1329c7142f11a68d"; $site_url = 'http://'.$_SERVER['SERVER_NAME'].'/Facebook/index.php'; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => TRUE )); $user = $facebook->getUser(); if($user){ // Get logout URL $logoutUrl = $facebook->getLogoutUrl(); }else{ // Get login URL $loginUrl = $facebook->getLoginUrl(array( 'scope' => 'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos', 'redirect_uri' => $site_url, )); } echo $user; ?>
<a href="<?=$loginUrl?>">
Upvotes: 0
Views: 297
Reputation: 44844
To get the user you need to use getUser
which is missing in your code. It should be as
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => TRUE
));
$user = $facebook->getUser();
if($user){
// Get logout URL
$logoutUrl = $facebook->getLogoutUrl();
}else{
// Get login URL
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
'redirect_uri' => $site_url,
));
}
getAccessToken()
will give you the current access token being used by the SDK.
Upvotes: 1