update = self.api.update_with_media('examples/banner.png', status=tweet_text)
self.assertIn(tweet_text + ' https://t.co', update.text)
- @tape.use_cassette('testgetuser.json')
+ @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.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')
upload_api=True, **kwargs
)
- def create_media_metadata(self, media_id, alt_text, *args, **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, **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}
}