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:
Source:stackexchange.com