0
我正在使用以下代碼嘗試使用FQL檢索頁面的見解。很明顯,我已經刪除了App ID,App Secret,URL和Object ID(在FQL查詢中)。返回0值的FQL查詢
頁面正確登錄用戶,並要求獲得「read_insights」權限。我以用戶身份登錄,該用戶是我嘗試訪問的網頁的管理員。
我得到的迴應是:
Array ([0] => Array ([metric] => page_like_adds [value] => 0))
我是全新的,以FQL,所以我相信我做了愚蠢的事情在這裏。
<?php
require_once('facebook/src/facebook.php');
define('APP_ID', '');
define('APP_SECRET', '');
$facebook = new Facebook(array(
'appId' => '',
'secret' => '',
'cookie' => true,
));
$app_id = "";
$app_secret = "";
$my_url = "";
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=read_insights";
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;
$token = file_get_contents($token_url);
$params = null;
parse_str($token, $params);
} else {
echo("");
}
$fql = "SELECT metric, value FROM insights WHERE object_id=OBJECT_ID AND metric='page_like_adds' AND end_time=1272351600 AND period=86400";
$fqlresponse = $facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
));
print_r($fqlresponse);
?>