Added getProfileImageUrl() to handle "users/profile_image" api call
This commit is contained in:
parent
7f93acb39e
commit
4d524fb654
1 changed files with 16 additions and 0 deletions
|
|
@ -402,6 +402,22 @@ class Twython(object):
|
|||
return urllib2.urlopen(r).read()
|
||||
except HTTPError, e:
|
||||
raise TwythonError("updateProfileImage() failed with a %d error code." % e.code, e.code)
|
||||
|
||||
def getProfileImageUrl(self, username, size=None, version=1):
|
||||
url = "http://api.twitter.com/%s/users/profile_image/%s.json" % (version, username)
|
||||
if size:
|
||||
url = self.constructApiURL(url, {'size':size})
|
||||
|
||||
try:
|
||||
client = httplib2.Http()
|
||||
client.follow_redirects = False
|
||||
resp = client.request(url, 'HEAD')[0]
|
||||
if resp['status'] not in ('301', '302', '303', '307'):
|
||||
raise TwythonError("getProfileImageUrl() failed to get redirect.")
|
||||
return resp['location']
|
||||
|
||||
except HTTPError, e:
|
||||
raise TwythonError("getProfileImageUrl() failed with a %d error code." % e.code, e.code)
|
||||
|
||||
@staticmethod
|
||||
def encode_multipart_formdata(fields, files):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue