facebook对象将accessToken返回为null

时间:2013-04-29 13:34:36

标签: php facebook facebook-access-token

我正在开发一个fecebook应用程序,使用php.i创建了一个应用程序并批准了权限然后我运行下面的代码,但它返回访问令牌为null,用户为0,这将是什么问题

require_once("facebook.php");
$config = array();
$config['appId'] = '****';
$config['secret'] = '*****';
$config['cookie'] = true;
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
var_dump($facebook);
$user = $facebook->getUser();
echo "user=".$user;

输出

object(Facebook)#1 (9) {
["sharedSessionID":protected]=>NULL
["appId":protected]=> string(15) "63270097007****"
["appSecret":protected]=>string(32) "****************"
["user":protected]=>NULL
["signedRequest":protected]=>NULL
["state":protected]=> string(32) "****************"
["accessToken":protected]=>NULL
["fileUploadSupport":protected]=>  bool(false)
["trustForwarded":protected]=>bool(false)
}
user=0

1 个答案:

答案 0 :(得分:0)

你可以在这里获得更多信息..

http://developers.facebook.com/docs/opengraph/howtos/publishing-with-app-token/

// Modify you code in this way.

require_once("facebook.php");
$config = array();
$config['appId'] = '****';
$config['secret'] = '*****';
$config['cookie'] = true;
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
var_dump($facebook);
$user = $facebook->getUser();

//Get Access Token URL
$access_token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$config['appId']."&client_secret=".$config['secret']."&grant_type=client_credentials";

//Get Access Token
$access_token = file_get_contents($access_token_url);
echo $access_token;

现在,您应该获得Acess令牌..