Facebook SDK永远不会设置$ user

时间:2012-08-03 19:54:21

标签: facebook authentication facebook-php-sdk facebook-authentication

我不知道我做错了什么。 它总是向我显示auth url,但我总是点击链接但仍然没有为我设置应用程序。

ini_set('include_path',"F:\fubolito\ajax.fubolito.py\inc");
include($_SERVER['DOCUMENT_ROOT'].'../ajax.fubolito.py/inc/config.global.php');
include('sdk/facebook.php');
$facebook = new Facebook(array('appId'  => $fb['app_id'],'secret' => $fb['secret'],
'cookie' => true,
));

$facebook->setAccessToken($_GET['code']);

$user = $facebook->getUser();

if(!$user)
echo '<a href="'.$facebook->getLoginUrl().'">Login</a>';

我做错了什么?

1 个答案:

答案 0 :(得分:1)

<?php 
require 'src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'YourAppId',
  'secret' => 'SecretKey',
  'cookie' => true, // enable optional cookie support
  ));
//  
try { $user = $facebook->getUser(); } catch (FacebookApiException $e) {  }
//
$access_token = $_SESSION['fb_YourAppID_access_token'];
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');

  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
if ($user) {
  $params = array (
  access_token => ''.$access_token.'',
  );
  $logoutUrl = $facebook->getLogoutUrl($params);
} else {
$params = array(
  scope => 'read_stream,publish_stream,publish_actions,read_friendlists',
  //redirect_uri => $url
  );
  $loginUrl = $facebook->getLoginUrl($params);
};

?>