X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/f0603331085c8baa2816fa08d6963fed8e521cf7..5a412b39408a2154c0f3537eb0b7f681d5744af5:/twitter/api.py diff --git a/twitter/api.py b/twitter/api.py index be0ef43..bed6275 100644 --- a/twitter/api.py +++ b/twitter/api.py @@ -205,6 +205,13 @@ class TwitterCall(object): for arg in ['media[]', 'banner', 'image']: if arg in kwargs: media = kwargs.pop(arg) + # Check if argument tells whether img is already base64 encoded + b64_convert = True + if "_base64" in kwargs: + b64_convert = not kwargs.pop("_base64") + if b64_convert: + import base64 + media = base64.b64encode(media) mediafield = arg break @@ -229,6 +236,7 @@ class TwitterCall(object): bod.append('--' + BOUNDARY) bod.append( 'Content-Disposition: form-data; name="%s"' % mediafield) + bod.append('Content-Transfer-Encoding: base64') bod.append('') bod.append(media) for k, v in kwargs.items(): @@ -322,6 +330,21 @@ class Twitter(TwitterCall): screen_name=','.join(A_LIST_OF_100_SCREEN_NAMES), \ _timeout=1) + # Overriding Method: GET/POST + # you should not need to use this method as this library properly + # detects whether GET or POST should be used, Nevertheless + # to force a particular method, use `_method` + t.statuses.oembed(_id=1234567890, _method='GET') + + # Send a tweet with an image included (or set your banner or logo similarily) + # By just reading your image from the web or a file in a string: + with open("example.png", "rb") as imagefile: + params = {"media[]": imagefile.read(), "status": "PTT"} + t.statuses.update_with_media(**params) + # Or by sending a base64 encoded image: + params = {"media[]": base64_image, "status": "PTT", "_base64": True} + t.statuses.update_with_media(**params) + Searching Twitter::