Last active
November 30, 2015 22:21
-
-
Save cjwinchester/6ba45bddbf7e377a434f to your computer and use it in GitHub Desktop.
Pythonically tweet an image (fetched from a URL) with your text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twitter import * | |
import requests | |
"Reference: https://pypi.python.org/pypi/twitter" | |
t = Twitter(auth=OAuth( | |
token, | |
token_secret, | |
consumer_key, | |
consumer_secret | |
)) | |
text = "Hello, here is a gif of John Ritter." | |
pic = "https://media.giphy.com/media/yGlu7x5jfWGZi/giphy.gif" | |
r = requests.get(pic, stream=True) | |
if r.status_code == 200: | |
r.raw.decode_content = True | |
imagedata = r.raw.read() | |
t_up = Twitter(domain='upload.twitter.com', auth=OAuth( | |
token, | |
token_secret, | |
consumer_key, | |
consumer_secret | |
)) | |
id_img = t_up.media.upload(media=imagedata)["media_id_string"] | |
t.statuses.update(status=text, media_ids=id_img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment