Python,如何将状态/update_with_media 发布到 Twitter? [英] Python, how to POST statuses/update_with_media to Twitter?

查看:35
本文介绍了Python,如何将状态/update_with_media 发布到 Twitter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用 Python 成功发布状态更新(推文):

I am able to successfully post status updates (tweet) in Python with that:

import urllib
import oauth2 as oauth

token = oauth.Token(access_token,access_token_secret)
consumer = oauth.Consumer(consumer_key,consumer_secret)

client = oauth.Client(consumer,token)

data = {'status': 'hello world'}
request_uri = 'https://api.twitter.com/1/statuses/update.json'

resp, content = client.request(request_uri, 'POST', urllib.urlencode(data))

现在我想知道我需要更改什么才能使用 update_with_media 发布图片?

Now I would like to know what I need to change to be able to post a picture with update_with_media?

推荐答案

最后我让它工作了,并想让那些正在为此苦苦挣扎的人知道我是如何用漂亮的 Twython 库轻松地做到这一点的,它抽象了功能很好:

At last i got it working and wanted to let know for people who is struggling with this how i finally easily did it with the nice Twython library, it abstract the functions nicely:

from twython import Twython

twitter = Twython(
    twitter_token = 'consumer_key',
    twitter_secret = 'consumer_secret',
    oauth_token = 'access_token',
    oauth_token_secret = 'access_token_secret'
)

twitter.updateStatusWithMedia('/home/blah/projects/pathexample/static/example.png', status='hello!')

这篇关于Python,如何将状态/update_with_media 发布到 Twitter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆