0

我不知道我做错了什么。它总是向我显示 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>';

我做错了什么?

4

1 回答 1

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);
};

?>
于 2012-08-04T16:47:42.150 回答