简体   繁体   中英

Facebook Graph API not returning all the fields of a perticular post

I was downloading all the posts of public pages. For example a recent post from 'Google's page in facebook looks like this :

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

This json object is one of the posts returned by the following code: (The code is from other stack-overflow page but there are limitations to post links)

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)

This post is supposed to have more fields. For example using the id associated with this post I use this link and see there are other fields. For example there are multiple pictures in this post and ' https://graph.facebook.com/v2.4/104958162837_10153902425172838?fields=picture&access_token=AccessToken ' will return :

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

Similarly it has other fields that are not shown in the result of the code. It should for example also show the likes to this post. So I have two questions:

  1. Why the result is not showing all the fields although those fields exist and can be found by querying the id of that post

  2. This post has multiple pictures but we are getting only one of the pictures and when I query for the number of likes and comments instead of returning likes or comments for the post, it return it for a certain picture.

Thank you.

  1. The answer to your first question is that the Facebook Graph API only returns a subset of fields by default. If you want different fields you need to specify which ones you want. This is mentioned in the Graph API docs :

By default, not all the fields in a node or edge are returned when you make a query. You can choose the fields (or edges) you want returned with the "fields" query parameter. This is really useful for making your API calls more efficient and fast.

In your case you could change your call to the following to retrieve (for example) the message and picture fields

graph.get(page_id + "/feed", page=False, retry=3, limit=100, fields="message,picture")
  1. The picture field for a post will only return a single picture ( The picture scraped from any link included with the post. ). To retrieve all of the pictures use the attachments edge which will return a list of all attached images (or videos etc).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM