Bastian
Bastian

Reputation: 5855

Python, how to POST statuses/update_with_media to Twitter?

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

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

Upvotes: 6

Views: 4671

Answers (2)

Raul Gomez
Raul Gomez

Reputation: 620

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

Upvotes: 10

Christian Witts
Christian Witts

Reputation: 11585

Something along these lines perhaps ?

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 just quickly scraped together by checking out Working with statuses/update_with_media and POST statuses/update_with_media and may not be correct.

Upvotes: 1

Related Questions