有没有办法通过 Graph API 获取特定帖子的 Facebook Insights?

Is there a way to obtain Facebook Insights for specific posts trough the Graph API?

抱歉打扰了一个愚蠢的问题,但我仍然是图表的初学者 API。一些背景知识可以更好地理解我的问题:我需要 运行 对 Facebook 页面进行分析(我不是其所有者而是管理员,规模较小,约 4000 个赞和约 150 posts ,每天或多或少一个)。我打算做的是:

  1. 通过图表API获取数据。也就是说,我最感兴趣的是检索每个 post

  2. 的消息、点赞数和覆盖率
  3. 导入R中的数据并识别异常值(我的意思是post的点赞数和到达率不符合平均值)

  4. 寻找这些消息之间的相关性(由于页面的性质,需要讨论广泛的主题,我想了解其中哪些产生最多的反应并相应地计划)

我已经做了分析"by hand",但我想测试一下是否可以在不涉及人工操作的情况下得出相同的结论。

我在网上查找了有关如何使用 python 中的图表 API 的教程,但未能找到全面的内容。我已经设置了 API 并获得了具有 manage_pagesread_insights 权限的永久页面令牌. 这是我在做什么的想法:`

def get_facebook_page_data(page_id, access_token):

website = "https://graph.facebook.com/v3.1/"

location = "%s/posts/" % page_id     

fields = "?fields=message,id" + \
"reactions.type(LIKE).limit(0).summary(total_count).as(reactions_like)"

authentication = "&limit=100&access_token=%s" % (access_token)

request_url = website + location + fields + authentication

data = json.loads(request_data_from_url(request_url))
return data`

所以,通过这个函数,我可以获取存储在 data 中的所有 post 的 ID、消息和点赞数,以及另一个功能我把所有东西都写在一个csv文件上。 第一个问题:我做错了什么吗? 第二个问题:我无法检索到很多信息。例如,在字段中添加 type 时,它表示已弃用(我是 运行ning python 3.7.3)

第三个问题:如何检索每个 post 的覆盖范围?我假设这是通过抓取洞察力获得的,因为我似乎没有弄对......我如何查询图表 API 以获取这些数据?

总的来说,我发现在构建链接时获取正确的关键字很麻烦。我已经安装了 facebook-sdk 但我不知道如何使用它(正如我所说,我是初学者)。你对此有什么建议吗?

非常感谢大家的回答,还有来自意大利的问候!

首先我建议使用最新版本的 API,目前是 5.0,关于你的问题:

Second question: I cannot retrieve a lot of information. For example, when adding type to the fields, it says that this is deprecated (I'm running python 3.7.3)

关于 Page Feed 的文档,请参阅 attachments 字段,例如,将其添加到请求中:

attachments.fields(media_type)

Third questions: how do I retrieve the reach for every post? I'm assuming this is obtained by scraping the insights, by I don't seem to get it right... How do I query the Graph API for those data?

关于 Page Insights 的文档,请参阅 page_impressions 字段,例如 return page_impressions 字段 lifetime 期间:

insights.period(lifetime).metric(post_impressions_unique)

一个完整的例子:

https://graph.facebook.com/v3.1/<PAGE-ID>/posts?fields=message,id,reactions.type(LIKE).limit(0).summary(total_count).as(reactions_like),insights.period(lifetime).metric(post_impressions_unique),attachments.fields(media_type)

会 return:

{
    "data": [{
                "message": "Hello",
                "id": "269816000129666_780829305694997",
                "reactions_like": {
                    "data": [],
                    "summary": {
                        "total_count": 0
                    }
                },
                "insights": {
                    "data": [{
                        "name": "post_impressions_unique",
                        "period": "lifetime",
                        "values": [{
                            "value": 15
                        }],
                        "title": "Lifetime Post Total Reach",
                        "description": "Lifetime: The number of people who had your Page's post enter their screen. Posts include statuses, photos, links, videos and more. (Unique Users)",
                        "id": "269816000129666_780829305694997/insights/post_impressions_unique/lifetime"
                    }],
                    "paging": {
                        "previous": "https://graph.facebook.com/v3.1/269816000129666_780829305694997/insights?access_token=EAAAAKq6xRNcBAOMKY3StjWXPgL1REATIfPFsyZCY21KDAnZAZB7MpKgNGCHRlKVt9bZBoVZAHpV0jqxZAAVZCOKDIh96YxvpxPaavR1AYK5EQCEEOSMKqz4ZAItcX9WvVfEEN5FzqgyoQWi8oKZBQmQB4Nf80SgicaesluNbI0hDMw2QAxfV9rAFpRc10Pop1d1vtVeziPEjEKwZDZD&metric=post_impressions_unique&period=lifetime&since=1573891200&until=1574064000",
                        "next": "https://graph.facebook.com/v3.1/269816000129666_780829305694997/insights?access_token=EAAAAKq6xRNcBAOMKY3StjWXPgL1REATIfPFsyZCY21KDAnZAZB7MpKgNGCHRlKVt9bZBoVZAHpV0jqxZAAVZCOKDIh96YxvpxPaavR1AYK5EQCEEOSMKqz4ZAItcX9WvVfEEN5FzqgyoQWi8oKZBQmQB4Nf80SgicaesluNbI0hDMw2QAxfV9rAFpRc10Pop1d1vtVeziPEjEKwZDZD&metric=post_impressions_unique&period=lifetime&since=1574236800&until=1574409600"
                    }
                },
                "attachments": {
                    "data": [{
                        "media_type": "photo"
                    }]
                }
            },
            {
                "message": "Say hello!",
                "id": "269816000129666_780826782361916",
                "reactions_like": {
                    "data": [],
                    "summary": {
                        "total_count": 0
                    }
                },
                "insights": {
                    "data": [{
                        "name": "post_impressions_unique",
                        "period": "lifetime",
                        "values": [{
                            "value": 14
                        }],
                        "title": "Lifetime Post Total Reach",
                        "description": "Lifetime: The number of people who had your Page's post enter their screen. Posts include statuses, photos, links, videos and more. (Unique Users)",
                        "id": "269816000129666_780826782361916/insights/post_impressions_unique/lifetime"
                    }],
                    "paging": {
                        "previous": "https://graph.facebook.com/v3.1/269816000129666_780826782361916/insights?access_token=EAAAAKq6xRNcBAOMKY3StjWXPgL1REATIfPFsyZCY21KDAnZAZB7MpKgNGCHRlKVt9bZBoVZAHpV0jqxZAAVZCOKDIh96YxvpxPaavR1AYK5EQCEEOSMKqz4ZAItcX9WvVfEEN5FzqgyoQWi8oKZBQmQB4Nf80SgicaesluNbI0hDMw2QAxfV9rAFpRc10Pop1d1vtVeziPEjEKwZDZD&metric=post_impressions_unique&period=lifetime&since=1573891200&until=1574064000",
                        "next": "https://graph.facebook.com/v3.1/269816000129666_780826782361916/insights?access_token=EAAAAKq6xRNcBAOMKY3StjWXPgL1REATIfPFsyZCY21KDAnZAZB7MpKgNGCHRlKVt9bZBoVZAHpV0jqxZAAVZCOKDIh96YxvpxPaavR1AYK5EQCEEOSMKqz4ZAItcX9WvVfEEN5FzqgyoQWi8oKZBQmQB4Nf80SgicaesluNbI0hDMw2QAxfV9rAFpRc10Pop1d1vtVeziPEjEKwZDZD&metric=post_impressions_unique&period=lifetime&since=1574236800&until=1574409600"
                    }
                },
                "attachments": {
                    "data": [{
                        "media_type": "photo"
                    }]
                }
            },