使用 facebook graph API 与 FQL 见解

发布于 2024-12-24 18:29:42 字数 1875 浏览 0 评论 0原文

我正在尝试从 Facebook 获取我拥有管理员权限的某些页面的见解。我能够使用图形 API 获取正确的数据,但是当我尝试使用 FQL 时,我得到一个空的 JSON 对象。知道可能是什么问题吗?

我认为查询是正确的,因为我没有收到任何 400/500 错误。我还认为权限是正确的,因为我使用与图形 API 解决方案相同的框架,并且工作正常。也许您需要额外的权限才能使用 FQL?我有manage_pages和read_insights。

我正在对 facebook 文档中的模板 URI 进行基本文本替换。

编辑:我认为问题可能是我实际上没有 read_insights 权限。我确实有manage_pages权限。也许这解释了为什么我可以通过 Graph API 而不能通过 FQL 访问见解?

图 API 查询:

string insight_str = "https://graph.facebook.com/APP_ID/insights/FIELD/FREQ?access_token=ACCESS_TOKEN";

string url = insight_str.Replace("FIELD", "page_impressions").Replace("FREQ","day").Replace("APP_ID", accounts[i].id).Replace("ACCESS_TOKEN", accounts[i].access_token);

https://graph.facebook.com/xxxxxxxx/insights /page_impressions/day?access_token=xxxxxxxx

Graph API 解析的 JSON 结果:

page_impressions
    2011-12-28  412
    2011-12-29  971
    2011-12-30  373

FQL 查询:

string query_str = "https://graph.facebook.com/fql?q=QUERY&access_token=ACCESS_TOKEN";

string query = "SELECT+metric,value+FROM+insights+WHERE+object_id=APP_ID+AND+metric='FIELD'+AND+end_time=1322722800+AND+period=86400";

string url = query_str.Replace("QUERY",query).Replace("FIELD","page_impressions").Replace("APP_ID",accounts[i].id).Replace("ACCESS_TOKEN",accounts[i].access_token);

https://graph.facebook.com/fql?q=SELECT+metric,value+FROM+insights+WHERE+object_id=xxxxxxxx+AND+metric='page_impressions'+AND+ end_time=1322722800+AND+period=86400&access_token=xxxxxxxx

FQL JSON 结果:

{"data":[]}

I'm trying to get insights from facebook for some pages I have admin rights to. I'm able to get the correct data with the graph API but when I try with FQL I get an empty JSON object. Any idea what the problem may be?

I think the query is correct because I do not get any 400/500 errors. I also think the permissions are correct because I'm using the same framwork with the graph API solution and it works fine. Maybe you need additional permissions to use FQL? I have manage_pages and read_insights.

I'm implementing with basic text replacement on the template URIs from facebook's documentation.

EDIT: I think the problem may be that I don't actually have the read_insights permission. I do have the manage_pages permission. Perhaps this explains why I can access insights through Graph API but not FQL?

Graph API query:

string insight_str = "https://graph.facebook.com/APP_ID/insights/FIELD/FREQ?access_token=ACCESS_TOKEN";

string url = insight_str.Replace("FIELD", "page_impressions").Replace("FREQ","day").Replace("APP_ID", accounts[i].id).Replace("ACCESS_TOKEN", accounts[i].access_token);

https://graph.facebook.com/xxxxxxxx/insights/page_impressions/day?access_token=xxxxxxxx

Graph API parsed JSON result:

page_impressions
    2011-12-28  412
    2011-12-29  971
    2011-12-30  373

FQL query:

string query_str = "https://graph.facebook.com/fql?q=QUERY&access_token=ACCESS_TOKEN";

string query = "SELECT+metric,value+FROM+insights+WHERE+object_id=APP_ID+AND+metric='FIELD'+AND+end_time=1322722800+AND+period=86400";

string url = query_str.Replace("QUERY",query).Replace("FIELD","page_impressions").Replace("APP_ID",accounts[i].id).Replace("ACCESS_TOKEN",accounts[i].access_token);

https://graph.facebook.com/fql?q=SELECT+metric,value+FROM+insights+WHERE+object_id=xxxxxxxx+AND+metric='page_impressions'+AND+end_time=1322722800+AND+period=86400&access_token=xxxxxxxx

FQL JSON result:

{"data":[]}

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

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

发布评论

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

评论(2

后eg是否自 2024-12-31 18:29:42

我对 Facebook C# SDK 版本 5.4.15.3.2 也有同样的问题(请参阅我的帖子 使用库 5.4.1 进行 FQL 查询时出错

我总是收到像你一样的空响应。

您必须拥有 read_insights 权限。

I have the same problem with Facebook C# SDK version 5.4.1 and 5.3.2 (see my post Error with FQL query with library 5.4.1)

I always receive an empty response like you.

You must have the read_insights permission.

画中仙 2024-12-31 18:29:42

我认为你的例子中的结束时间略有偏差。它需要在太平洋标准时间恰好午夜落下。当我将时间向前移动一个小时,到 1322726400 时,我得到了一个值。

I think the end time in your example is slightly off. It needs to fall exactly at midnight PST. I obtained a value once I moved the time forward an hour, to 1322726400.

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