]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/api.py
friends_timeline is deprecated in API v1.1, remove it from all examples and ircbot
[z_archive/twitter.git] / twitter / api.py
index 42068c69bd2e5bd280234ef71a969fbe2332e1cb..d1ded3431934092fb8b8651b1195bde8de0ee9e9 100644 (file)
@@ -196,16 +196,45 @@ class TwitterCall(object):
         uriBase = "http%s://%s/%s%s%s" %(
                     secure_str, self.domain, uri, dot, self.format)
 
+        # Catch media arguments to handle oauth query differently for multipart
+        media = None
+        for arg in ['media[]', 'banner', 'image']:
+            if arg in kwargs:
+                media = kwargs.pop(arg)
+                mediafield = arg
+                break
+
         headers = {'Accept-Encoding': 'gzip'} if self.gzip else dict()
         body = None; arg_data = None
         if self.auth:
             headers.update(self.auth.generate_headers())
-            arg_data = self.auth.encode_params(uriBase, method, kwargs)
-            if method == 'GET':
+            # Use urlencoded oauth args with no params when sending media
+            # via multipart and send it directly via uri even for post
+            arg_data = self.auth.encode_params(uriBase, method,
+                {} if media else kwargs )
+            if method == 'GET' or media:
                 uriBase += '?' + arg_data
             else:
                 body = arg_data.encode('utf8')
 
+        # Handle query as multipart when sending media
+        if media:
+            BOUNDARY = "###Python-Twitter###"
+            bod = []
+            bod.append('--' + BOUNDARY)
+            bod.append('Content-Disposition: form-data; name="%s"' %
+                mediafield)
+            bod.append('')
+            bod.append(media)
+            for k, v in kwargs.items():
+                bod.append('--' + BOUNDARY)
+                bod.append('Content-Disposition: form-data; name="%s"' % k)
+                bod.append('')
+                bod.append(v)
+            bod.append('--' + BOUNDARY + '--')
+            body = '\r\n'.join(bod)
+            headers['Content-Type'] = 'multipart/form-data; boundary=%s' % BOUNDARY
+
         req = urllib_request.Request(uriBase, body, headers)
         return self._handle_response(req, uri, arg_data, _timeout)
 
@@ -260,11 +289,8 @@ class Twitter(TwitterCall):
         # Get your "home" timeline
         t.statuses.home_timeline()
 
-        # Get a particular friend's timeline
-        t.statuses.friends_timeline(id="billybob")
-
-        # Also supported (but totally weird)
-        t.statuses.friends_timeline.billybob()
+        # Get a particular friend's tweets
+        t.statuses.user_timeline(user_id="billybob")
 
         # Update your status
         t.statuses.update(