1

我尝试使用 Graph API 执行 FQL 查询以获取 Insights 计数器的值,但没有成功。

有谁知道我该怎么做?

我使用“Facebook C# SDK”版本 5.4.1、C# 4.0。

如果我使用文档中提供的 C# 示例代码

    var fb = new FacebookClient(m_accessToken);
    dynamic result = fb.Query("SELECT name, uid FROM user WHERE uid= me()");

我收到了很好的回应

{"name":"","uid":100002632407830}

使用相同的语法,如果我请求“pages_fans”洞察计数器并使用库 5.4.1

var fb = new FacebookClient(m_accessToken);
  dynamic result = fb.Query("SELECT metric, value FROM insights WHERE object_id=6176018219 AND metric='page_fans' AND end_time=end_time_date('2011-12-31') AND period=period('lifetime')");

我总是收到一个空的回复

 {[]}

使用相同的代码但使用库 5.2.1 我总是收到很好的响应

 {[{"metric":"page_fans","value":"125535"}]}

这是这里描述的相同问题:使用库 5.4.1 的 FQL 查询出错,但使用另一种语法。

目前我使用 REST API(使用库 5.2.1)使用 FQL Insights 查询,但我想使用 Graph API(使用库 5.4.1)迁移到 FQL Insights 查询,因为不推荐使用 REST API。

错误在哪里:

  1. 在我的语法请求中?
  2. 在“Facebook C# SDK”库中?
  3. 在 Facebook 服务器上?

此致。

4

4 回答 4

2

我向 Facebook Graph API Explorer 提出了请求

https://graph.facebook.com/fql?q=SELECT metric, value FROM insights
WHERE object_id=6176018219 AND metric='page_fans' AND
end_time=end_time_date('2011-12-31') AND period=period('lifetime')

我总是收到一个空洞的回应。

{
  "data": [
  ]
}

这是 Facebook 的错误。

在 Facebook 上创建了一个关于它的错误:http: //developers.facebook.com/bugs/232510993491615 ?browse=search_4f08c675cce9d2265724293

于 2012-01-09T15:39:44.883 回答
1

确保您在获得访问令牌时拥有正确的权限

<fb:login-button perms="read_insights"></fb:login-button>
于 2012-10-23T15:54:01.367 回答
1

我找到了另一种方法来检索可靠工作的信息

我发现了另一种检索见解的方法,这似乎是可靠的。文档在这里http://developers.facebook.com/docs/reference/api/insights/

有更多选项来允许格式和期间的变化 - 下面的例子。

https://graph.facebook.com/2439131959/insights/application_active_users/[period]?format=json&since=[timestamp]&until=[timestamp]&access_token=[access_token]

period 是日、月、周、生命周期。时间戳必须是有效的 PST 午夜。access_token = 可能是。1. 不需要许可的指标什么都没有。2. app_id|secret_code 或 3. 您的身份验证令牌授予您访问应用程序或页面的洞察数据(即所有者或洞察用户)的访问权限。

C# SDK 示例:

FacebookClient fbClient = new FacebookClient([appID], [secret]);

        DateTime untilDate= (new DateTime([Now].Year, [Now].Month, [Now].Day));
        DateTime sinceDate= (new DateTime([Now].Year, [Now].Month, [Now].Day)).AddDays(-1);
        TimeSpan t = (untilDate- new DateTime(1970, 1, 1));
        int timestampUntil = (int)t.TotalSeconds;
        t = (sinceDate- new DateTime(1970, 1, 1));
        int timeStampSince = (int)t.TotalSeconds;



        var result = (IDictionary<string, object>)fbClient.Get([appID] + "/insights/" + [metricID] + "/" + [period] + "?format=json&since="+timeStampSince+"&until="+timestampUntil );
         Console.WriteLine(result["data"]);
于 2012-01-18T16:20:46.220 回答
0

此问题与Facebook C# SDK相关。

您可以做的最好的事情可能是在 codeplex 上提交错误,并替换end_time_dateto"time in seconds"periodto的用法"lifetime"

于 2012-01-06T20:17:00.263 回答