无法通过Python的Facebook Graph API向Facebook页面发布带图像的附件
我的Django网站需要定期在网站的Facebook页面上发布内容。我通过一个自定义应用程序,使用Python的Facebook图形API,能够将内容作为附件发布到Facebook页面上。
但是,当我尝试同时发布一个附件和一张图片时,图片却没有显示出来。
这是代码(除了图片,其他内容我在Facebook页面上都能看到):
....
import facebook
# our fb app. can post to fb page via "FB_PAGE_ACCESS_TOKEN_FOR_FB_APP" token
graph = facebook.GraphAPI(settings.FB_PAGE_ACCESS_TOKEN_FOR_FB_APP)
attachment = {}
message = ''
# don't know why it's not working!
attachment['media'] = [ {"type": "image", "src": {{FILE_URL}}, "href": {{page_url}}} ]
attachment['name'] = {{obj.title}}
attachment['description'] = {{obj.small_desc}}
attachment['link'] = {{page_url}}
attachment['caption'] = {{site}}
graph.put_wall_post(message, attachment, settings.FACEBOOK_PAGE)
出了什么问题?
1 个回答
1
你应该用 picture
,而不是 media
。
而且你只需要提供图片的链接就可以了。
attachment['picture'] = {{FILE_URL}}