开发者

FQL queries returning 0 value

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);

?>


With your FQL:

$fql = "SELECT metric, value FROM insights WHERE object_id=OBJECT_ID AND        metric='page_like_adds' AND end_time=1272351600 AND period=86400";

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜