i recently made a test app in facebook, the app is a website app and i only need user login so that i can access user info from within the app using the php sdk, when i first tested it, the login process works perfectly, the problem is, when i reach the test page, it is completely blank, whereas i expect it to echo: HELLO NAME, where "NAME" would be my name, here's the code, i won't post the app id, secret,etc, as those certainly work, due to the login process being fine:
$app_id = "xxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxx";
$my_url = "http://www.anithro.com/anithroproject/login.php/";
session_start();
$code = $_REQUEST["code"];
if(empty($code)) {
// Redirect to Login Dialog
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'] . "&scope=user_birthday,read_stream";
echo("<script> top.location.href='" . $dialog_url . "'</script>");
if($_SESSION['state'] && ($_SESSION['state'] === $_REQUEST['state'])) {
// state variable matches
$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);
$_SESSION['access_token'] = $params['access_token'];
$graph_url = "https://graph.facebook.com/me?access_token="
. $_SESSION['access_token'];
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
}
i have followed the code to the letter, why can't i access the user variables?thanks in advance.you can try visiting the url i've given and see, it's just blank.
Did you test the access_token you are using if it is authenticated? You can use this for debugging tools: https://developers.facebook.com/tools/
You can also try this link: https://github.com/facebook/facebook-php-sdk The PHP SDK here uses a class to get the basic info of the user that logs in. Check the example folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.