1

我正在使用 php 开发一个 fecebook 应用程序。我创建了一个应用程序并批准了权限,然后我运行下面的代码,但它返回访问令牌为空,用户为 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
4

1 回答 1

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;

现在,您应该获得访问令牌..

于 2013-04-29T13:45:10.623 回答