简体   繁体   中英

Facebook getUser() return 0

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?>">

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM