Warm tip: This article is reproduced from serverfault.com, please click

How to add an image to an existing facebook post using API and python?

发布于 2020-12-01 08:29:41

I'm using facebook graph API to update/edit the text of a specific post on my page

import facebook

page_token = '...'
fb = facebook.GraphAPI(access_token = page_token, version="2.12")
page_id = '...'
post_id = '...'
fb.put_object(parent_object = page_id + '_' + post_id,
              connection_name = '',
              message = 'new text')

now I'm trying to add a local image (stored in the same folder of the python script) to this post but I don't understand how to properly do it, I tried

fb.put_object(parent_object=page_id+'_'+post_id, connection_name='', message='new text', source = open('out.png', 'rb'))

and

fb.put_object(parent_object=page_id+'_'+post_id, connection_name='', message='new text', object_attachment = open('out.png', 'rb'))

but none of them works. Hints?

p.s. these are the permission of my app

pages_show_list
pages_read_engagement
pages_read_user_content
pages_manage_posts
pages_manage_engagement

EDIT: I tried with the function put_photo but it creates a new post adding the image to it, while I need to add an image to an already existing post

Questioner
sound wave
Viewed
0
18.9k 2020-12-09 03:02:20