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

Adding images to Page Posts #260

Closed josylad closed 2 months ago

josylad commented 2 months ago

Hello, Firstly, thanks for building this library, it is a lifesaver.

Right now, I am trying to post both text and images on Facebook pages and I have the code below.

post_data = {
        "message": content,  # You can customize the message
          "url": image_url,  # Replace this with the URL of your image
  }

api.post_object(object_id=page_id, connection="feed", data=post_data,)

I am passing an image URL but the images are not published on the page, only the text. Any help?

josylad commented 2 months ago

any help? @MerleLiuKun @pietzschke

josylad commented 2 months ago

I figured it out. below is how to post images.

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 = the text you want to include in the post.