self.username = None
self.secure = secure
- def _get_oauth_url(self, endpoint):
- if self.secure:
+ def _get_oauth_url(self, endpoint, secure=False):
+ if self.secure or secure:
prefix = 'https://'
else:
prefix = 'http://'
except Exception, e:
raise TweepError(e)
+ def get_xauth_access_token(self, username, password):
+ """
+ Get an access token from an username and password combination.
+ In order to get this working you need to create an app at
+ http://twitter.com/apps, after that send a mail to api@twitter.com
+ and request activation of xAuth for it.
+ """
+ try:
+ url = self._get_oauth_url('access_token', secure=True) # must use HTTPS
+ request = oauth.OAuthRequest.from_consumer_and_token(
+ oauth_consumer=self._consumer,
+ http_method='POST', http_url=url,
+ parameters = {
+ 'x_auth_mode': 'client_auth',
+ 'x_auth_username': username,
+ 'x_auth_password': password
+ }
+ )
+ request.sign_request(self._sigmethod, self._consumer, None)
+
+ resp = urlopen(Request(url, data=request.to_postdata()))
+ self.access_token = oauth.OAuthToken.from_string(resp.read())
+ return self.access_token
+ except Exception, e:
+ raise TweepError(e)
+
def get_username(self):
if self.username is None:
api = API(self)