我对以下代码感到疯狂:
<?php
//Code of http://example.com/facebook/
require_once("../settings.php"); //Providing some settings
function authorize()
{
header("HTTP/1.1 303 See Other");
header("Location: https://www.facebook.com/dialog/oauth?client_id=".urlencode($GLOBALS["FacebookConfig"]["appId"])."&redirect_uri=".urlencode("http://example.com/facebook/".(isset($_GET["delete"])?'?delete':''))."&scope=read_mailbox,offline_access");
exit();
}
require_once("SDK/facebook.php");
if(!isset($_GET["code"]))
{
authorize();
}
$facebook = new Facebook($GLOBALS["FacebookConfig"]); //$GLOBALS["FacebookConfig"] is defined and set correctly
$user=$facebook->getUser(); //retreive User ID
if(!$user)
{
header("HTTP/1.1 303 See Other");
$LoginURL=$facebook->getLoginUrl();
header("Location: ".$LoginURL); //Endless redirect here
exit();
}
?>
我的问题是$user
始终存在0
,因此客户端被无限重定向。但我看不出$user
总是留下来的理由0
。通常它应该是当前登录的 facebook 用户的用户 ID。
编辑:$GLOBALS["FacebookConfig"]
设置settings.php
如下:
$GLOBALS["FacebookConfig"] = array();
$GLOBALS["FacebookConfig"]['appId'] = 'appID'; //appID replaced
$GLOBALS["FacebookConfig"]['secret'] = 'appSecret'; //appSecret replaced
$GLOBALS["FacebookConfig"]['fileUpload'] = false;