【问题标题】:Facebook Graph API not returning all the fields of a perticular postFacebook Graph API 未返回特定帖子的所有字段
【发布时间】:2016-02-12 05:41:09
【问题描述】:

我正在下载公共页面的所有帖子。例如,Facebook 中“Google 页面”的最新帖子如下所示:

{
        "created_time": "2016-02-04T02:55:11+0000",
        "message": "We hope you\u2019re just as excited about the Year of the Monkey as we are!  So excited, we\u2019ve been hunting around Street View for monkey sightings. Here are a few we found so far...want to help us find more 'Monkeys of StreetView'? #monkeyview goo.gl/8LhqMe",
        "story": "Google added 4 new photos to the album: Monkeys of StreetView.",
        "id": "104958162837_10153902425172838"
    }

此json对象是以下代码返回的帖子之一:(代码来自其他stack-overflow页面,但帖子链接有限制)

from facepy import GraphAPI
import json
page_id = "Google"

access_token = "AccessToken"

graph = GraphAPI(access_token)
data = graph.get(page_id + "/feed", page=False, retry=3, limit=100)

with open('content.json', 'w') as outfile:
     json.dump(data, outfile, indent = 4)

这篇文章应该有更多的领域。例如,使用与这篇文章关联的 ID,我使用这个链接并查看还有其他字段。例如,这篇文章中有多张图片,'https://graph.facebook.com/v2.4/104958162837_10153902425172838?fields=picture&access_token=AccessToken' 将返回:

{ "图片": "https://scontent.xx.fbcdn.net/hphotos-xfa1/v/t1.0-0/s130x130/12654459_10153902425172838_781196554188881203_n.jpg?oh=eef2aa5a6297767d9bd924c1e3311afc&oe=576EC3CA", “id”:“104958162837_10153902425172838” }

同样,它还有其他未显示在代码结果中的字段。例如,它还应该显示对这篇文章的喜欢。 所以我有两个问题:

  1. 为什么结果没有显示所有字段,尽管这些字段存在并且可以通过查询该帖子的 id 找到

  2. 这篇文章有多张图片,但我们只得到其中一张图片,当我查询点赞和 cmets 的数量而不是返回帖子的点赞或 cmets 时,它会返回某张图片。

谢谢。

【问题讨论】:

    标签: python facebook-graph-api


    【解决方案1】:
    1. 第一个问题的答案是 Facebook Graph API 默认只返回字段的子集。如果您想要不同的字段,您需要指定您想要的字段。 the Graph API docs中提到了这一点:

    默认情况下,不是节点或边中的所有字段都返回时 进行查询。您可以选择要返回的字段(或边缘) 使用“字段”查询参数。这对制作非常有用 您的 API 调用更高效、更快速。

    在您的情况下,您可以将调用更改为以下内容以检索(例如)消息和图片字段

    graph.get(page_id + "/feed", page=False, retry=3, limit=100, fields="message,picture")
    
    1. 帖子的图片字段将只返回一张图片 (The picture scraped from any link included with the post.)。要检索所有图片,请使用 attachments edge,它将返回所有附加图片(或视频等)的列表。

    【讨论】:

    • 非常感谢您的回答。对此,我真的非常感激。请问一下,点赞问题怎么解决。它不是返回对帖子的赞,而是返回对其中一张图片的赞。
    • 你打什么电话来获得点赞?调用 graph.get(page_id + "/likes") 应该返回帖子的点赞数。
    • 我使用的是这个链接:api_endpoint+page_id+'/likes?summary=true&access_token='+access_token
    • 例如:graph.facebook.com/v2.4/104958162837_10153902425172838/… 这是谷歌 Facebook 页面在 2 月 3 日晚上 9:55 发布的帖子 ID,其中包含多张图片。它正在返回对某张图片的喜欢。
    • 另外一个问题是这个链接graph.facebook.com/v2.4/…(104958162837_10153902425172838是一个帖子ID。)只打印帖子的相同ID而不是帖子的消息。为什么会这样?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多