问题:我想获取我 Facebook 墙上的所有帖子。
描述:为此,我正在使用访问令牌。但我无法检索我 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 参数时,它什么也不显示。我无法找出错误。