繁体   English   中英

使用facepy从帖子中获取“图片”

[英]Getting 'picture' from post using facepy

在使用facepy软件包从小组中获取帖子后,我注意到正在检索某些图片,而另一些则没有。 我知道有些帖子没有附加图片,但是我发现其他一些在数据字典中没有“图片”键条目,但是当我在浏览器中打开帖子时,我可以看到实际上附有图片到职位。 这是我正在使用的代码。

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

关于如何获取这些图像的任何想法吗?

UPD:无论如何,您都从json接收数据。 尝试这个:

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

该查询返回以下数据,其中fullsize_src是图片的链接:

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

      }
    },
  . . .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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