Fixed import errors with Twython, cleaned up some OAuth self.references junk, and fixed showUser to make requests even if there's no authentication being done (thanks to Risto for tipping me off to the last one ;)
This commit is contained in:
parent
b54782c744
commit
3369f7d81d
1 changed files with 23 additions and 21 deletions
34
twython.py
34
twython.py
|
|
@ -98,7 +98,6 @@ class setup:
|
||||||
elif consumer_secret is not None and consumer_key is not None:
|
elif consumer_secret is not None and consumer_key is not None:
|
||||||
self.consumer = oauth.OAuthConsumer(self.consumer_key, self.consumer_secret)
|
self.consumer = oauth.OAuthConsumer(self.consumer_key, self.consumer_secret)
|
||||||
self.connection = httplib.HTTPSConnection(SERVER)
|
self.connection = httplib.HTTPSConnection(SERVER)
|
||||||
self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
|
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
@ -122,19 +121,21 @@ class setup:
|
||||||
response = connection.getresponse()
|
response = connection.getresponse()
|
||||||
return simplejson.load(response.read())
|
return simplejson.load(response.read())
|
||||||
|
|
||||||
def getUnauthorisedRequestToken(self, consumer, connection, signature_method=self.signature_method):
|
def getUnauthorisedRequestToken(self, consumer, connection, signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()):
|
||||||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, consumer, http_url=self.request_token_url)
|
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, consumer, http_url=self.request_token_url)
|
||||||
oauth_request.sign_request(signature_method, consumer, None)
|
oauth_request.sign_request(signature_method, consumer, None)
|
||||||
resp = fetch_response(oauth_request, connection)
|
resp = fetch_response(oauth_request, connection)
|
||||||
return oauth.OAuthToken.from_string(resp)
|
return oauth.OAuthToken.from_string(resp)
|
||||||
|
|
||||||
def getAuthorizationURL(self, consumer, token, signature_method=self.signature_method):
|
def getAuthorizationURL(self, consumer, token, signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()):
|
||||||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, http_url=self.authorization_url)
|
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, http_url=self.authorization_url)
|
||||||
oauth_request.sign_request(signature_method, consumer, token)
|
oauth_request.sign_request(signature_method, consumer, token)
|
||||||
return oauth_request.to_url()
|
return oauth_request.to_url()
|
||||||
|
|
||||||
def exchangeRequestTokenForAccessToken(self, consumer, connection, request_token=self.request_token, signature_method=self.signature_method):
|
def exchangeRequestTokenForAccessToken(self, consumer, connection, request_token, signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()):
|
||||||
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=request_token, http_url=self.access_token_url)
|
# May not be needed...
|
||||||
|
self.request_token = request_token
|
||||||
|
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token = request_token, http_url=self.access_token_url)
|
||||||
oauth_request.sign_request(signature_method, consumer, request_token)
|
oauth_request.sign_request(signature_method, consumer, request_token)
|
||||||
resp = fetch_response(oauth_request, connection)
|
resp = fetch_response(oauth_request, connection)
|
||||||
return oauth.OAuthToken.from_string(resp)
|
return oauth.OAuthToken.from_string(resp)
|
||||||
|
|
@ -381,20 +382,21 @@ class setup:
|
||||||
|
|
||||||
...will result in only publicly available data being returned.
|
...will result in only publicly available data being returned.
|
||||||
"""
|
"""
|
||||||
if self.authenticated is True:
|
apiURL = ""
|
||||||
apiURL = ""
|
if id is not None:
|
||||||
if id is not None:
|
apiURL = "http://twitter.com/users/show/%s.json" % id
|
||||||
apiURL = "http://twitter.com/users/show/%s.json" % id
|
if user_id is not None:
|
||||||
if user_id is not None:
|
apiURL = "http://twitter.com/users/show.json?user_id=%s" % `user_id`
|
||||||
apiURL = "http://twitter.com/users/show.json?user_id=%s" % `user_id`
|
if screen_name is not None:
|
||||||
if screen_name is not None:
|
apiURL = "http://twitter.com/users/show.json?screen_name=%s" % screen_name
|
||||||
apiURL = "http://twitter.com/users/show.json?screen_name=%s" % screen_name
|
if apiURL != "":
|
||||||
try:
|
try:
|
||||||
return simplejson.load(self.opener.open(apiURL))
|
if self.authenticated is True:
|
||||||
|
return simplejson.load(self.opener.open(apiURL))
|
||||||
|
else:
|
||||||
|
return simplejson.load(urllib2.urlopen(apiURL))
|
||||||
except HTTPError, e:
|
except HTTPError, e:
|
||||||
raise TwythonError("showUser() failed with a %s error code." % `e.code`, e.code)
|
raise TwythonError("showUser() failed with a %s error code." % `e.code`, e.code)
|
||||||
else:
|
|
||||||
raise AuthError("showUser() requires you to be authenticated.")
|
|
||||||
|
|
||||||
def getFriendsStatus(self, id = None, user_id = None, screen_name = None, page = "1"):
|
def getFriendsStatus(self, id = None, user_id = None, screen_name = None, page = "1"):
|
||||||
"""getFriendsStatus(id = None, user_id = None, screen_name = None, page = "1")
|
"""getFriendsStatus(id = None, user_id = None, screen_name = None, page = "1")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue