Python, how to set POST / update_with_media status on Twitter?

I can successfully post status updates (tweet) in Python with:

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))

Now I would like to know what I need to change in order to publish the image using update_with_media?

+5
source share
2 answers

Finally, I got his job and wanted to tell people who are struggling with this, as I finally did it easily with a good Twython library, it perfectly abstracts the functions:

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!')
+9
source

Something like that?

data = {'status': 'hello world'
      , 'media': ['image.jpg']
      }
request_uri = 'https://upload.twitter.com/1/statuses/update_with_media.json'

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

This was simply quickly scraped by checking the Work with statuses / update _with_media and Statuses POST / update_with_media and may be incorrect.

+1
source

All Articles