Publishing pictures to Twitter via python

2019-09-20 11:19发布

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.

2条回答
劳资没心,怎么记你
2楼-- · 2019-09-20 11:50

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.

查看更多
我只想做你的唯一
3楼-- · 2019-09-20 11:54

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)
查看更多
登录 后发表回答