FQL 查询返回 0 值
我正在使用以下代码尝试使用 FQL 检索页面的见解。显然,我已经删除了应用程序 ID、应用程序密钥、URL 和对象 ID(在 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);
?>
I am using the following code to try and retrieve a Page's insights using FQL. Obviously I've stripped out the App ID, App Secret, URL, and Object ID (in the FQL query).
The page logs in the user correctly, and asks for the "read_insights" permission. I am logging in as a user that is an admin for the Page I am trying to access.
The response I'm getting is:
Array ( [0] => Array ( [metric] => page_like_adds [value] => 0 ) )
I'm brand new to FQL, so I'm sure I'm doing something dumb here.
<?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);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 FQL:
您选择指标“page_like_adds”,即“主页内容的点赞数”,直到“1272351600”,即“2010 年 4 月 27 日星期二”。
所以我想,你的查询不是你想要的。
您希望从页面中获得哪些洞察指标?
我建议阅读: https://developers.facebook.com/docs/reference/fql /insights/(官方文档也是 FQL 指标)
您还可以尝试使用 Graph API 来获取见解:
https://developers.facebook.com/tools/explorer/
With your FQL:
you're selecting the metric "page_like_adds", which is "Likes of your Page's content" till "1272351600", which is "Tuesday, April 27th 2010".
So I guess, your query is not, what you want.
Which insigh metrics do you want from your page?
I suggest to read: https://developers.facebook.com/docs/reference/fql/insights/ (the official Docs too FQL metrics)
You may also try the Graph API to access insights:
https://developers.facebook.com/tools/explorer/