1

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?

keith.g
  • 900
  • 9
  • 19
  • The API probably searches for specific HTML tags. Maybe there is a way to add those? Otherwise, you would need to code a scraper on your own. – Philipp Braun Jan 24 '16 at 12:42

1 Answers1

0

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…",

      }
    },
  . . .
alex10
  • 2,726
  • 3
  • 22
  • 35
  • I'd rather not scrape the enter HTML to get details which are already exposed through the facepy library. – keith.g Jan 25 '16 at 00:08
  • Ok, I've updated the answer using fql and facepy https://facepy.readthedocs.org/en/latest/usage/graph-api.html. – alex10 Jan 25 '16 at 03:03
  • Thanks for your reply. Unfortunately the posts which return a 'media' subdict using FQL Query are the same posts which return a 'picture' subdict using Graph API. A good example of this may be observed in the following query: `SELECT post_id, message, attachment FROM stream WHERE source_id=480958408759774 AND post_id='480958408759774_484159318439683'` does not return any of the images shown in the actual [post](https://www.facebook.com/480958408759774/posts/484159318439683). – keith.g Jan 26 '16 at 00:41