我成为 Facebook 开发人员已有一段时间了,但我对新的 Facebook 应用程序布局重新开始,并坚持了第一步。所以显然我的旧身份验证方法不再起作用了。
为了解决这个问题,我尝试了http://developers.facebook.com/docs/authentication/上作为示例给出的那个。但是,它似乎在 Internet Explorer 上根本不起作用。
下面是我的代码:
<?php
$app_id = "-----";
$app_secret = "------";
$my_url = "http://apps.facebook.com/myapp/";
require('facebook-php-sdk-2343fca/src/facebook.php');
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,));
$session = $facebook->getSession();
session_start();
$code = $_REQUEST["code"];
echo $_REQUEST['state']." == ".$_SESSION['state'];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'] . '&scope=publish_stream,read_stream,user_photos,friends_photos,user_events,friends_events';
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_REQUEST['state'] == $_SESSION['state']) {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
//echo("Hello " . $user->name);
//My app goes here!
} else {
echo("The state does not match. You may be a victim of CSRF.");
}
?>
到目前为止,我所知道的问题与$_SESSION['state']
;
任何帮助将不胜感激!