问题
Is anyone using the twitter module for python (https://github.com/sixohsix/twitter/tree/master) able to publish pictures on twitter account? Everything works fine with publishing text to status, but I couldn't figure how to publish pictures. Thanks for the help.
Adding my code, as suggested in the comments (thanks for that!):
import twitter
t = twitter.Twitter(auth=twitter.OAuth('PAR1', 'PAR2','PAR3', 'PAR4')) #autentication is fine.
#t.statuses.update(status="Hello World!") #this command works fine!
t.updateStatusWithMedia('http://url_of_image', status="Hello World!") #that's what I need to do.
回答1:
If you are using the external twitter
module, I assume that installing other external libraries is acceptable to you. You could try tweetphoto
to upload images via an API. You can figure it out here.
回答2:
I guess the twitter module doesn't deal with the method POST, or I couldn't make it work. I could do it with Twython:
import twython
import urllib
t = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
pic urllib.urlopen('http://pic.png')
t.update_status_with_media(status='Status', media=pic)
来源:https://stackoverflow.com/questions/19729532/publishing-pictures-to-twitter-via-python