問題:我想獲取我的臉書牆上的所有信息。 描述:爲此,我正在使用訪問令牌。但我無法檢索我的臉書牆上的帖子。以下是我用過的代碼。如何使用用戶訪問令牌獲取Facebook信息
<?php
$app_id = "xxxxxxxxxxxxxx";
$app_secret = " xxxxxxxxxxxxxxxxxxx ";
$my_url = "http://localhost:8088/fb/testing.php";
session_start();
$code = $_REQUEST["code"];
if(empty($code))
{
$_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=publish_stream,read_stream";
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_SESSION['state'] && ($_SESSION['state'] === $_REQUEST['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);
echo $response;
$_SESSION['access_token'] = $params['access_token'];
$graph_url = "https://graph.facebook.com/me/feed/?access_token="
. $params['access_token'];
$response = json_decode(file_get_contents($graph_url));
if($response)
echo $response;
echo("Hello " .$user);
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
?>
在這裏,當我打印$ user參數時,它什麼也不顯示。我無法找出錯誤。請幫我解決這個問題。它非常緊急。我會非常感激。
哪裏是$用戶的聲明? –