我已经成为一名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']
;
任何帮助都是非常有用的!
答案 0 :(得分:1)
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
您可以在此处阅读更多内容:How to properly handle session and access token with Facebook PHP SDK 3.0?