[Fixed]-Django. Tweet image saved on ImageField

1👍

Since the upload_with_media endpoint has been deprecated, see here, I’m going to suggest you to use the following method:

Use the absolute path to the file

media_ids = api.media_upload(filename=model_object.image.file.name)

Twitter API will respond with a long integer cached in the media_ids variable.

Finally, use the update_status endpoint:

params = {'status': 'chop chop chop', 'media_ids': [media_ids.media_id_string]}
response = api.update_status(**params)

For reference, see the method definitions in tweepy, and their correspondence in Twitter api:

  1. Tweepy: media_upload
  2. Tweepy: update_status
  3. Twitter API: update endpoint
  4. Twitter API: media_upload endpoint

Leave a comment