X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/9f04d75d1196d1fa4ccf89b2adf081e7bba08d21..e4bec6bdddd1e2b2b0f4db950adf28d0b711f44a:/twitter/api.py diff --git a/twitter/api.py b/twitter/api.py index 42068c6..d1ded34 100644 --- a/twitter/api.py +++ b/twitter/api.py @@ -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(