Post picture on Facebook

    0

    2

    Social Media Posting

    Put a picture that shows on the feed of a specific page.

    To get your token, see https://developers.facebook.com/.

    For this recipe, we store the facebook page id and the token as environment variable.

    import os
    import facebook
    
    def post_facebook(message, image_path):
      PAGE_ID = os.environ["FACEBOOK_PAGE_ID"]
    	PAGE_ACCESS_TOKEN = os.environ["FACEBOOK_PAGE_ACCESS_TOKEN"]
       link = "https://example.org"
       with open(image_path, 'rb') as picture_file:
        graph = facebook.GraphAPI(PAGE_ACCESS_TOKEN)
        photo_put = graph.put_photo(image=picture_file, message=message, published=True, link=link)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.