Getting 'picture' from post using facepy

435 views Asked by At

After getting posts from a group using the facepy package I noticed that some picture are being retrieved whilst others are not. I am aware that some posts do not have any pictures attached but I have found others which do not have a 'picture' key entry in the data dict yet when I open the post in my browser I can see that there are in fact images attached to the post. This is the code that I am using.

from facepy import GraphAPI

ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
graph = GraphAPI(ACCESS_TOKEN)
groupIDs = (['xxxxxxxxxxxxxxx'])

groupData = graph.get(groupIDs[0] + "/feed", page=False, retry=3, limit=600)
dataDict = groupData['data']

for data in dataDict:
    try:
        picture = property['picture']
    except Exception as e:
        #no picture available
        continue

Any idea of how to get these images?

1

There are 1 answers

3
alex10 On

UPD: In any case you receive data from a json. Try this:

graph = GraphAPI(access_token)
group_id = "xxxxxxxxxxxxxxx"
graph.fql( SELECT post_id, message, attachment FROM stream WHERE source_id=group_id)

This query returns the following data, where fullsize_src is the link to the picture:

{
  "data": [
    {
      "message": "test...",
      "post_id": "348119228599690_933534210058186",
      "updated_time": 1453685624,
      "attachment": {
        "media": [
          {
            "href": "http://zakarpattya.net.ua/News/150883-V-Uzhhorodi-vidkryvsia-suchasnyi-Zakarpatskyi-TSentr-Zoru-FOTO",
            "alt": "test…",
            "src": "https://external.xx.fbcdn.net/safe_image.php?d=AQBHiLIIZmJx9TcO&w=130&h=130&url=http%3A%2F%2Fzakarpattya.net.ua%2Fpostimages%2Fpub%2F2016%2F01%2F530a82085993ba504fea316c82f1f1d609414bd8f744cc8b517dc8507e388164.jpg&cfs=1",
            "fullsize_src": "https://external.xx.fbcdn.net/safe_image.php?d=AQBPhLO5Dzhycx5M&w=720&h=720&url=http%3A%2F%2Fzakarpattya.net.ua%2Fpostimages%2Fpub%2F2016%2F01%2F530a82085993ba504fea316c82f1f1d609414bd8f744cc8b517dc8507e388164.jpg&cfs=1",
            "type": "link"
          }
        ],
        "name": "test",
        "href": "http://l.facebook.com/l.php?u=http%3A%2F%2Fzakarpattya.net.ua%2FNews%2F150883-V-Uzhhorodi-vidkryvsia-suchasnyi-Zakarpatskyi-TSentr-Zoru-FOTO&h=lAQF-JR_g&s=1",
        "caption": "zakarpattya.net.ua",
        "description": "test…",

      }
    },
  . . .