title: Code to Automatically Post Images To My Twitter Account via Python Script
body: <p>I want to post images programmatically on my own (not other peoples') twitter account. To that end, I tried using the tweepy library -- but they have a method called api.update_with_media('the image') which does not work.</p>
  
  <p>It seems twitter has deprecated this method:
  ...statuses/update_with_media
  (sorry for the truncated html -> I'm new here, so they won't let me post too many links)</p>
  
  <p>Twitter instructs us to use this instead:
  ...public/uploading-media</p>
  
  <p>Basically, this is a 2-step method.
  Step 1) Upload media and get some ID in json
  Step 2) Use this ID to update a status</p>
  
  <p>Both of these steps require authentication. The problem is that the twitter libraries, (which can be found here twitter-libraries) don't actually support this new method. They all have the simple one from before in their documentation.</p>
  
  <p>It seems possibly this one fixed it, but the docs didn't get updated (I didn't actually play with it too deeply -- it is at this point that I decided to contract this out). It can be found <a href="https://github.com/sixohsix/twitter/blob/master/tests/test_sanity.py#L86-L103" rel="nofollow">here</a>.</p>
  
  <p>It seems the options are:</p>
  
  <p>1) build the code from scratch, including
  a) the OAuth  (breakable, complex)
  b) the update status script (re-writing code the libraries already have)</p>
  
  <p>2) Same as above but use a generic OAuth library</p>
  
  <p>3) Find a library that supports the new upload method -- there may very well be one in that list, but it would involve reading through documentation and testing, or </p>
  
  <p>4) Some other idea I didn't think of</p>
  
  <p>I made sure this works for text updates -- just replace 
  api.update_with_media(image) 
  with 
  api.update_status(status='Hey'). </p>
  
  <p>For reference, here's the code I'm using: </p>
  
  <p>`
  import urllib
  import tweepy</p>
  
  <p>@app.route('/')
  def testing(): </p>
  
  <pre><code>consumer_key = '---'
  consumer_secret = '---'
  access_token = '---'
  access_token_secret = '---'
  
  #OAuth process, using the keys and tokens
  auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  auth.set_access_token(access_token, access_token_secret)
  
  #Creation of the actual interface, using authentication
  api = tweepy.API(auth)
  
  #should encode the image - I tried this several different way
  image = urllib.urlopen('image-url')
  
  try:
      api.update_with_media(image)
  except Exception, e:
      print e
  
  return "OK"
  </code></pre>
  
  <p>`</p>