Modified blukUserLookup:

* version argument was ignored
* user_id and screen_name lists were not url-escaped, and always ended
with a trailing comma
* unknown parameter 'lol=1' removed
* allow other arguments to users/lookup to be added (kwargs)
* added http headers to request
This commit is contained in:
Erik Scheffers 2011-01-25 15:17:49 +08:00 committed by Ryan McGrath
parent 6f38c4c27d
commit 7f93acb39e

View file

@ -256,25 +256,22 @@ class Twython(object):
except HTTPError, e: except HTTPError, e:
raise TwythonError("shortenURL() failed with a %s error code." % `e.code`) raise TwythonError("shortenURL() failed with a %s error code." % `e.code`)
def bulkUserLookup(self, ids = None, screen_names = None, version = None): def bulkUserLookup(self, ids = None, screen_names = None, version = 1, **kwargs):
""" bulkUserLookup(self, ids = None, screen_names = None, version = None) """ bulkUserLookup(self, ids = None, screen_names = None, version = 1, **kwargs)
A method to do bulk user lookups against the Twitter API. Arguments (ids (numbers) / screen_names (strings)) should be flat Arrays that A method to do bulk user lookups against the Twitter API. Arguments (ids (numbers) / screen_names (strings)) should be flat Arrays that
contain their respective data sets. contain their respective data sets.
Statuses for the users in question will be returned inline if they exist. Requires authentication! Statuses for the users in question will be returned inline if they exist. Requires authentication!
""" """
apiURL = "http://api.twitter.com/1/users/lookup.json?lol=1" if ids:
if ids is not None: kwargs['user_id'] = ','.join(map(str, ids))
apiURL += "&user_id=" if screen_names:
for id in ids: kwargs['screen_names'] = ','.join(screen_names)
apiURL += `id` + ","
if screen_names is not None: lookupURL = Twython.constructApiURL("http://api.twitter.com/%d/users/lookup.json" % version, kwargs)
apiURL += "&screen_name="
for name in screen_names:
apiURL += name + ","
try: try:
resp, content = self.client.request(apiURL, "GET") resp, content = self.client.request(lookupURL, "GET", headers = self.headers)
return simplejson.loads(content) return simplejson.loads(content)
except HTTPError, e: except HTTPError, e:
raise TwythonError("bulkUserLookup() failed with a %s error code." % `e.code`, e.code) raise TwythonError("bulkUserLookup() failed with a %s error code." % `e.code`, e.code)