Python Forum
How to add an image to an existing facebook post using python graph API?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add an image to an existing facebook post using python graph API?
#1
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 (notice that I don't have to create a new post and attach a photo (for which we simply use put_photo function) but I have to attach a photo to an existing post).
What I tried so far

    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 (there are no errors when running the code, but the image is not added to the post).
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python modules to extract data from a graph? bigmit37 5 14,327 Apr-09-2021, 02:15 PM
Last Post: TysonL
  Python Matplotlib: How do I plot lines with different end point in the same graph? JaneTan 0 344 Feb-28-2021, 11:56 AM
Last Post: JaneTan
  Issues Scraping Facebook using facebook_scraper DustinKlent 3 705 Dec-06-2020, 10:27 PM
Last Post: bowlofred
  Python Paramiko mkdir command overwriting existing folder. How can i stop that? therenaydin 1 828 Aug-02-2020, 11:13 PM
Last Post: therenaydin
  PIL Image / python-resize-image AttributeError sallyjc81 1 1,079 Aug-02-2020, 12:06 AM
Last Post: scidam
  Python I/O: input a graph anata2047 4 968 Jun-19-2020, 01:02 PM
Last Post: deanhystad
  Post JSON dat and Image vijsi 2 925 Oct-03-2019, 01:35 PM
Last Post: vijsi
  How to create an autocomplete method that search an existing trie in python nanoprogrammer 0 1,141 Jul-20-2019, 12:09 AM
Last Post: nanoprogrammer
  Graphing three database in one graph Python r_e 1 1,026 Jun-20-2019, 05:10 PM
Last Post: r_e
  python rrdtool graph creation issue anna 0 2,842 Sep-10-2018, 11:10 AM
Last Post: anna

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020