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
  How to accept facebook cookies using python selenium? pablo86ad 0 162 Apr-06-2024, 09:19 PM
Last Post: pablo86ad
  Issues Scraping Facebook using facebook_scraper DustinKlent 4 3,628 Mar-19-2024, 08:17 PM
Last Post: Mostafa_heikal
  Python best library for Excel reports & review of existing code MasterOfDestr 4 606 Feb-14-2024, 03:39 PM
Last Post: MasterOfDestr
  Python beginner that needs an expression added to existing script markham 1 695 Sep-04-2023, 05:24 AM
Last Post: Pedroski55
  DELETE Post using Python FaceBook Graph API BIG_PESH 0 1,451 Mar-24-2022, 08:28 PM
Last Post: BIG_PESH
  Upload image to Instagram using python/selenium using image URL failed, need help greenpine 5 5,442 Feb-22-2022, 09:42 PM
Last Post: snippsat
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,308 Dec-04-2021, 08:33 PM
Last Post: Ascalon
  Python modules to extract data from a graph? bigmit37 5 22,370 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 1,575 Feb-28-2021, 11:56 AM
Last Post: JaneTan
  Python Paramiko mkdir command overwriting existing folder. How can i stop that? therenaydin 1 3,213 Aug-02-2020, 11:13 PM
Last Post: therenaydin

Forum Jump:

User Panel Messages

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