From: Harmon Date: Fri, 12 Feb 2021 04:49:37 +0000 (-0600) Subject: Merge branch 'master' into video-upload X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f72da6e75e7c1d8b8cf529fda58923f6a4e83dd9;p=tweepy.git Merge branch 'master' into video-upload --- f72da6e75e7c1d8b8cf529fda58923f6a4e83dd9 diff --cc tests/test_api.py index 8349678,33a5890..0f40f08 --- a/tests/test_api.py +++ b/tests/test_api.py @@@ -113,24 -113,12 +113,24 @@@ class TweepyAPITests(TweepyTestCase) update = self.api.update_with_media('examples/banner.png', status=tweet_text) self.assertIn(tweet_text + ' https://t.co', update.text) + @tape.use_cassette('testmediauploadpng.yaml', serializer='yaml') + def testmediauploadpng(self): + self.api.media_upload('examples/banner.png') + + @tape.use_cassette('testmediauploadgif.yaml', serializer='yaml') + def testmediauploadgif(self): + self.api.media_upload('examples/animated.gif') + + @tape.use_cassette('testmediauploadmp4.yaml', serializer='yaml') + def testmediauploadmp4(self): + self.api.media_upload('examples/video.mp4') + - @tape.use_cassette('testgetuser.json') + @tape.use_cassette('testgetuser.yaml', serializer='yaml') def testgetuser(self): - u = self.api.get_user('Twitter') + u = self.api.get_user(screen_name='Twitter') self.assertEqual(u.screen_name, 'Twitter') - u = self.api.get_user(783214) + u = self.api.get_user(user_id=783214) self.assertEqual(u.screen_name, 'Twitter') @tape.use_cassette('testlookupusers.json') diff --cc tweepy/api.py index 503e76f,dd389a5..a452f82 --- a/tweepy/api.py +++ b/tweepy/api.py @@@ -440,24 -361,10 +440,24 @@@ class API upload_api=True, **kwargs ) + @payload('media') + def chunked_upload_finalize(self, media_id, *args, **kwargs): + """ :reference https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/api-reference/post-media-upload-finalize + """ + headers = {'Content-Type': 'application/x-www-form-urlencoded'} + post_data = { + 'command': 'FINALIZE', + 'media_id': media_id + } + return self.request( + 'POST', 'media/upload', *args, headers=headers, + post_data=post_data, upload_api=True, **kwargs + ) + - def create_media_metadata(self, media_id, alt_text, *args, **kwargs): + def create_media_metadata(self, media_id, alt_text, **kwargs): """ :reference: https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create """ - kwargs['json_payload'] = { + json_payload = { 'media_id': media_id, 'alt_text': {'text': alt_text} }