Server Twitter Integration

From packets2photons
Jump to navigation Jump to search

Already well documented here: https://pypi.org/project/twython/

#!/usr/bin/python3

import sys
from twython import Twython

from twitter_auth import (
    consumer_key,
    consumer_secret,
    access_token,
    access_token_secret
)

twitter = Twython(
    consumer_key,
    consumer_secret,
    access_token,
    access_token_secret
)

message = "Quenda image test"
image = open(sys.argv[1], 'rb')
response = twitter.upload_media(media=image)
media_id = [response['media_id']]
twitter.update_status(status=message, media_ids=media_id)
print("Tweeted: %s" % message)