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