最近Facebookでテストアプリを作成しました。このアプリはウェブサイトアプリであり、ユーザーログインのみが必要です。これにより、php sdkを使用してアプリ内からユーザー情報にアクセスできます。最初にテストしたとき、ログインプロセスは完全に機能します。問題は、テストページに到達すると完全に空白になるのに対し、エコーすることを期待していることです。HELLONAME、ここで「NAME」は私の名前です。ここにコードがあります。アプリID、シークレットなどを投稿しません。 、ログインプロセスが正常であるため、これらは確かに機能します。
$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.");
}
}
私は手紙のコードに従いましたが、なぜユーザー変数にアクセスできないのですか?事前に感謝します。私が与えたURLにアクセスしてみてください、それは空白です。