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)