python-facebook icon indicating copy to clipboard operation
python-facebook copied to clipboard

Post with an image

Open astagi opened this issue 2 years ago • 1 comments

Hi,

do you have any example for posting a text with a local image? I got this code example but I don't know which parameters include in the request.

api = GraphAPI(
    app_id=FACEBOOK_APP_ID,
    app_secret=FACEBOOK_APP_SECRET,
    access_token=FACEBOOK_TOKEN
)
data = api.post_object(
    object_id=FACEBOOK_PAGE_ID,
    connection="feed",
    params={
        "fields": "id,message,created_time,from",
    },
    data={
        "message": status
    },
)

Thank you!

astagi avatar Aug 03 '23 08:08 astagi

You can follow the docs to publish photos

MerleLiuKun avatar Aug 07 '23 02:08 MerleLiuKun

Hello @astagi were you able to figure this out?

josylad avatar May 02 '24 08:05 josylad

Unfortunately not @josylad I'd like to have a complete example with a local image to upload..

astagi avatar May 02 '24 11:05 astagi

Unfortunately not @josylad I'd like to have a complete example with a local image to upload..

oh! Well, I was able to figure it out. @astagi

image_data = {"url": image_url, "message": content}

#upload an image 
uploaded_image = api.post_object(object_id=page_id, connection="photos", data=image_data)

change connection to "photos" message = text you want to post on FB.

josylad avatar May 02 '24 11:05 josylad

#260

MerleLiuKun avatar May 06 '24 06:05 MerleLiuKun