sns-sdks / python-facebook

A simple Python wrapper for facebook graph api :sparkles: :cake: :sparkles: .
https://sns-sdks.github.io/python-facebook/
322 stars 84 forks source link

Post with an image #232

Closed astagi closed 2 months ago

astagi commented 11 months ago

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!

MerleLiuKun commented 11 months ago

You can follow the docs to publish photos

josylad commented 2 months ago

Hello @astagi were you able to figure this out?

astagi commented 2 months ago

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

josylad commented 2 months ago

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.

MerleLiuKun commented 2 months ago

260