Sketched out a basic method for oauth to work in my app...
This commit is contained in:
parent
e32209bf2b
commit
f70e76acc2
|
@ -9,8 +9,8 @@ from urllib2 import HTTPError,URLError
|
|||
import avcache
|
||||
|
||||
# These are the global constants for the twitter oauth entry for our app
|
||||
CONSUMER_KEY = jGu64TPCUtyLZKyWyMJldQ
|
||||
CONSUMER_SECRET = lTRrTyvzRfJab5HsAe16zkV8tqFVRp0k0cTfHL0l4GE
|
||||
CONSUMER_KEY = 'jGu64TPCUtyLZKyWyMJldQ'
|
||||
CONSUMER_SECRET = 'lTRrTyvzRfJab5HsAe16zkV8tqFVRp0k0cTfHL0l4GE'
|
||||
|
||||
|
||||
class CustomApi(OAuthApi):
|
||||
|
@ -20,11 +20,13 @@ class CustomApi(OAuthApi):
|
|||
instantiated
|
||||
'''
|
||||
|
||||
def __init__(self, access_token):
|
||||
def __init__(self, username, access_token):
|
||||
OAuthApi.__init__(self, CONSUMER_KEY, CONSUMER_SECRET, access_token)
|
||||
self.lock = RLock()
|
||||
self.sig_proxy = SigProxy()
|
||||
|
||||
self.username = username
|
||||
|
||||
thread = GetUserLists(api=self)
|
||||
thread.sig_proxy.connect('lists-ready', self.on_lists_ready)
|
||||
thread.start()
|
||||
|
@ -463,5 +465,15 @@ def dms_to_statuses(direct_messages):
|
|||
return statuses
|
||||
|
||||
|
||||
def get_api(username, password):
|
||||
def get_access_token():
|
||||
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)
|
||||
|
||||
auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token)
|
||||
return auth_api.getAccessToken()
|
||||
|
|
23
hrafn.py
23
hrafn.py
|
@ -59,6 +59,9 @@ class Hrafn():
|
|||
db_file = os.path.expanduser(config.get('global', 'dbfile'))
|
||||
self.db = shelve.open(db_file)
|
||||
|
||||
if not self.db.has_key('tokens'):
|
||||
self.db['tokens'] = {}
|
||||
|
||||
if not self.db.has_key('active_page'):
|
||||
self.db['active_page'] = 0
|
||||
|
||||
|
@ -67,11 +70,11 @@ class Hrafn():
|
|||
|
||||
# Now set up the accounts and their corresponding APIs
|
||||
self.accounts = {}
|
||||
for item in config.sections():
|
||||
if (re.match(r'account', item)):
|
||||
username = config.get(item, 'username')
|
||||
self.accounts[username] = apithreads.get_api(username=username, password=config.get(item, 'password'))
|
||||
self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready)
|
||||
for token in self.db['tokens']:
|
||||
api = CustomApi(token)
|
||||
username = api.username
|
||||
self.accounts[username] = api
|
||||
self.accounts[username].sig_proxy.connect('lists-ready', self.on_lists_ready)
|
||||
|
||||
if not self.db.has_key('active_user'):
|
||||
self.db['active_user'] = self.accounts.keys()[0]
|
||||
|
@ -547,6 +550,16 @@ class Hrafn():
|
|||
print 'debug: thread: ' + thread.name
|
||||
|
||||
|
||||
def on_file_add_account(self, widget):
|
||||
token = apithreads.get_access_token()
|
||||
api = apithreads.CustomApi(token)
|
||||
username = api.username
|
||||
|
||||
if not self.accounts.has_key(username):
|
||||
tokens = self.db['tokens']
|
||||
tokens.append(token)
|
||||
self.db['tokens'] = tokens
|
||||
self.accounts['username'] = api
|
||||
|
||||
### end class Hrafn
|
||||
|
||||
|
|
|
@ -14,9 +14,11 @@ __author__ = "Hameedullah Khan <hameed@hameedkhan.net>"
|
|||
__version__ = "0.2"
|
||||
|
||||
|
||||
from twitter import Api, User
|
||||
from twitter import Api
|
||||
from twitter_pb2 import User
|
||||
|
||||
import simplejson, oauth
|
||||
import simplejson
|
||||
import oauth.oauth as oauth
|
||||
|
||||
|
||||
|
||||
|
|
Reference in New Issue
Block a user