Publishing pictures to Twitter via python

不打扰是莪最后的温柔 提交于 2019-12-25 17:39:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!