diff --git a/apithreads.py b/apithreads.py index a739aa5..442ea82 100644 --- a/apithreads.py +++ b/apithreads.py @@ -7,6 +7,8 @@ import twitter_pb2 from oauthtwitter import OAuthApi from urllib2 import HTTPError,URLError import avcache +import webbrowser +from time import sleep # These are the global constants for the twitter oauth entry for our app CONSUMER_KEY = 'jGu64TPCUtyLZKyWyMJldQ' @@ -465,15 +467,29 @@ def dms_to_statuses(direct_messages): return statuses -def get_access_token(): +def get_access_token(window): auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET) request_token = auth_api.getRequestToken() authorization_url = auth_api.getAuthorizationURL(request_token) - # Get authentication from url... buh? - - print 'debug: authorization_url: ' + authorization_url - exit(1) - + webbrowser.open(authorization_url) auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token) - return auth_api.getAccessToken() + + dialog = gtk.Dialog("Enter PIN", window, gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + entry = gtk.Entry() + dialog.vbox.pack_start(entry) + response = dialog.run() + dialog.hide() + + if response == gtk.RESPONSE_OK: + pin = entry.get_text() + + try: + access_token = auth_api.getAccessToken(pin) + except HTTPError: + access_token = None + + return access_token + + else: + return None diff --git a/hrafn.py b/hrafn.py index f3e68e0..722ec7a 100755 --- a/hrafn.py +++ b/hrafn.py @@ -536,7 +536,10 @@ class Hrafn(): def on_file_add_account(self, widget): - token = apithreads.get_access_token() + token = apithreads.get_access_token(self.window) + if token is None: + return + api = apithreads.CustomApi(token) username = api.username diff --git a/oauthtwitter.py b/oauthtwitter.py index a43b8dc..3e7bfd4 100755 --- a/oauthtwitter.py +++ b/oauthtwitter.py @@ -181,8 +181,11 @@ class OAuthApi(Api): signin_url = self.getAuthorizationURL(token, url) return signin_url - def getAccessToken(self, url=ACCESS_TOKEN_URL): - token = self._FetchUrl(url, no_cache=True) + def getAccessToken(self, pin=None, url=ACCESS_TOKEN_URL): + params = None + if pin: + params = {'oauth_verifier': pin} + token = self._FetchUrl(url, parameters=params, no_cache=True) return oauth.OAuthToken.from_string(token) def getRequestToken(self, url=REQUEST_TOKEN_URL):