From 9df10773388c2b4783afff79fc98157b2533b13f Mon Sep 17 00:00:00 2001 From: Jamie Winspear Date: Thu, 21 Sep 2017 16:39:32 +0100 Subject: [PATCH] Setting media_category when needed for bulk upload of larger files --- tweepy/api.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index b3d95cc..74d9e1c 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -1464,13 +1464,19 @@ class API(object): BOUNDARY = b'Tw3ePy' body = list() if command == 'init': - body.append( - urlencode({ - 'command': 'INIT', - 'media_type': file_type, - 'total_bytes': file_size - }).encode('utf-8') - ) + query = { + 'command': 'INIT', + 'media_type': file_type, + 'total_bytes': file_size, + } + if file_type in IMAGE_MIMETYPES: + if file_type == 'image/gif': + query['media_category'] = 'tweet_gif' + else: + query['media_category'] = 'tweet_image' + elif file_type == 'video/mp4': + query['media_category'] = 'tweet_video' + body.append(urlencode(query).encode('utf-8')) headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' } -- 2.25.1