In [7]:
import os
from dotenv import load_dotenv
from twython import Twython
from datetime import datetime, timedelta
import os.path
from os import path

# Get file names
date = datetime.now() - timedelta(days = 1) 
date_string = date.strftime('%-m-%-d-%y')
first_pic = '/Users/kootsoop/Pictures/COVID-19-FORECAST-' + date_string + '.png'
second_pic = '/Users/kootsoop/Pictures/COVID-19-FORECAST-HISTORY-' + date_string + '.png'

load_dotenv(dotenv_path='/Users/kootsoop/.env')

API_KEY = os.getenv('TWITTER_API_KEY')
API_SECRET_KEY = os.getenv('TWITTER_API_SECRET_KEY')
ACCESS_TOKEN=os.getenv('TWITTER_ACCESS_TOKEN')
ACCESS_TOKEN_SECRET=os.getenv('TWITTER_ACCESS_TOKEN_SECRET')

twitter = Twython(API_KEY, API_SECRET_KEY, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

image1_ids = ''
image2_ids = ''

if path.exists(first_pic):
    print('First pic found : ' + first_pic)
    image1_open = open(first_pic, 'rb')
    image1_ids = twitter.upload_media(media=image1_open)
    

if path.exists(second_pic):
    print('Second pic found : ' + second_pic)
    image2_open = open(second_pic, 'rb')
    image2_ids = twitter.upload_media(media=image2_open)
    
twitter.update_status(status=date_string + ': Forecast date for 200k deaths in the USA. #tracking200k',media_ids=[image1_ids['media_id'], image2_ids['media_id']])

# page_access_token = os.getenv('FACEBOOK_ACCESS_TOKEN')
# graph = facebook.GraphAPI(page_access_token)
# graph.put_object("me", "feed", message="Posting on my wall1!")


---------------------------------------------------------------------------
GraphAPIError                             Traceback (most recent call last)
<ipython-input-7-9e59ca7c2cd2> in <module>
     41 page_access_token = os.getenv('FACEBOOK_ACCESS_TOKEN')
     42 graph = facebook.GraphAPI(page_access_token)
---> 43 graph.put_object("me", "feed", message="Posting on my wall1!")
     44 

~/opt/anaconda3/lib/python3.7/site-packages/facebook/__init__.py in put_object(self, parent_object, connection_name, **data)
    190             "{0}/{1}/{2}".format(self.version, parent_object, connection_name),
    191             post_args=data,
--> 192             method="POST",
    193         )
    194 

~/opt/anaconda3/lib/python3.7/site-packages/facebook/__init__.py in request(self, path, args, post_args, files, method)
    311 
    312         if result and isinstance(result, dict) and result.get("error"):
--> 313             raise GraphAPIError(result)
    314         return result
    315 

GraphAPIError: (#200) If posting to a group, requires app being installed in the group, and \
          either publish_to_groups permission with user token, or both manage_pages \
          and publish_pages permission with page token; If posting to a page, \
          requires both manage_pages and publish_pages as an admin with \
          sufficient administrative permission

In [ ]: