【问题标题】:Is there a way to obtain Facebook Insights for specific posts trough the Graph API?有没有办法通过 Graph API 获取特定帖子的 Facebook Insights?
【发布时间】:2019-11-22 16:59:08
【问题描述】:

很抱歉提出一个愚蠢的问题,但我仍然是 Graph API 的初学者。一些背景知识可以更好地理解我的问题:我需要在 Facebook 页面上进行分析(我不是该页面的所有者,而是管理员,体积小,约 4000 个赞和约 150 个帖子,每天或多或少一个)。我打算做的是:

  1. 通过 Graph API 获取数据槽。也就是说,我最感兴趣的是检索每个帖子的消息、点赞数和覆盖率

  2. 在R中导入数据,识别异常值(我的意思是点赞和到达率不符合均值的帖子)

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

我已经“手动”进行了分析,但我想测试是否可以在不涉及人工操作的情况下得出相同的结论。

我在网上查看了有关如何在 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 中的所有帖子的 ID、消息和点赞数,而通过另一个函数,我可以将所有内容写入 csv 文件。 第一个问题:我做错了吗? 第二个问题:我无法检索到很多信息。例如,当向字段添加 type 时,它表示已弃用(我正在运行 python 3.7.3)

第三个问题:如何检索每个帖子的覆盖面?我假设这是通过收集见解获得的,但我似乎没有得到正确的结果......如何查询 Graph API 以获取这些数据?

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

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

【问题讨论】:

    标签: python facebook facebook-graph-api


    【解决方案1】:

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

    第二个问题:我无法检索到很多信息。例如, 向字段添加类型时,它表示已弃用(我是 运行 python 3.7.3)

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

    attachments.fields(media_type)
    

    第三个问题:如何检索每个帖子的覆盖面?我是 假设这是通过收集见解获得的,我似乎没有 做对了...如何在 Graph API 中查询这些数据?

    关于Page Insights 的文档,请参见page_impressions 字段,例如,以便为lifetime 句点返回page_impressions 字段:

    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)

    将返回:

    {
        "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"
                        }]
                    }
                },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 2015-08-05
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      • 2016-06-01
      相关资源
      最近更新 更多