如何使用 Facebook Graph API 执行 FQL Insights 查询

发布于 2024-12-25 16:58:52 字数 1266 浏览 1 评论 0原文

我尝试使用 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”见解计数器并使用 library 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 服务器上?

此致。

I try without success to execute a FQL query using Graph API to get the value of Insights counters.

Does anyone know how I can do this?

I use "Facebook C# SDK" version 5.4.1, C# 4.0.

If I use C# sample code provided in the documentation

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

I receive a good response

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

With the same syntax, If I request "pages_fans" Insights counter and use library 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')");

I receive always an empty response

 {[]}

With the same code but with library 5.2.1
I receive always a good response

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

It is the same problem described here : Error with FQL query with library 5.4.1 but with another syntax.

Currently I use FQL Insights queries using REST API (with libary 5.2.1) but I want to migrate to FQL Insights queries using the Graph API (with library 5.4.1) because the REST API is deprecated.

Where is the bug:

  1. In my syntax request?
  2. In the "Facebook C# SDK" library?
  3. On Facebook server?

Best regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

君勿笑 2025-01-01 16:58:52

我使用 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

I made a request with the 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')

I receive always an empty response.

{
  "data": [
  ]
}

It is a Facebook's bug.

A bug was created about it on Facebook : http://developers.facebook.com/bugs/232510993491615?browse=search_4f08c675cce9d2265724293

画骨成沙 2025-01-01 16:58:52

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

我找到了另一种检索似乎可靠的见解的方法。
此处找到文档 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]

周期为日、月、周, 寿命。
时间戳只能是有效的 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"]);

I found another way to retrieving the info which works reliably

I found another way of retrieving insights which seems to be reliable.
documentation found here http://developers.facebook.com/docs/reference/api/insights/.

with more options to allow format and period changes - below example.

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

period is day, month, week, lifetime.
timestamp has to be a valid PST midnight only.
access_token = could be.
1. nothing for the metrics that don't need permission.
2. app_id|secret_code or
3. your authentication token granted that you have access to the insight data of the application or pages (ie owner or insight users).

C# sdk example:

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"]);
晚雾 2025-01-01 16:58:52

获取访问令牌时,请确保您拥有正确的权限

<fb:login-button perms="read_insights"></fb:login-button>

Make sure you have the correct permissions when you get your Access Token

<fb:login-button perms="read_insights"></fb:login-button>
对你再特殊 2025-01-01 16:58:52

此问题与 Facebook C# SDK 相关。

您能做的最好的事情可能就是在 codeplex 上提交错误,并将 end_time_date 的用法替换为 “以秒为单位的时间”,将 period 替换为 “一生”

This issue related to Facebook C# SDK.

Probably best thing you can do is file a bug on codeplex, and replace usage of end_time_date to "time in seconds" and period to "lifetime".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文