]> jfr.im git - z_archive/twitter.git/blobdiff - README
add doc for new twitter way to send medias (close #279 )
[z_archive/twitter.git] / README
diff --git a/README b/README
index 74e1a3cd4a8b77e24a79a0b531edcfec1e253de3..d45e4f5a0d6103c550777b73fa373eee9f4d3e31 100644 (file)
--- a/README
+++ b/README
@@ -119,15 +119,24 @@ t.users.lookup(
 # 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:
-status = "PTT ★"
+# Send images along with your tweets:
+# - first just read images from the web or from files the regular way:
 with open("example.png", "rb") as imagefile:
-    params = {"media[]": imagefile.read(), "status": status}
-t.statuses.update_with_media(**params)
-
-# Or by sending a base64 encoded image:
-params = {"media[]": base64_image, "status": status, "_base64": True}
+    imagedata = imagefile.read()
+# - then upload medias one by one on Twitter's dedicated server
+#   and collect each one's id:
+t_up = Twitter(domain='upload.twitter.com',
+    auth=OAuth(token, token_key, con_secret, con_secret_key))
+id_img1 = str(t_up.media.upload(media=imagedata)["media_id"])
+id_img2 = str(t_up.media.upload(media=imagedata)["media_id"])
+# - finally send your tweet with the list of media ids:
+t.statuses.update(status="PTT ★", media_ids=",".join([id_img1, id_img2]))
+
+# Or send a tweet with an image (or set a logo/banner similarily)
+# using the old deprecated method that will probably disappear some day
+params = {"media[]": imagedata, "status": "PTT ★"}
+# Or for an image encoded as base64:
+params = {"media[]": base64_image, "status": "PTT ★", "_base64": True}
 t.statuses.update_with_media(**params)
 ```