socializer/src/sessionmanager/vkSessionHandler.py

25 lines
967 B
Python
Raw Normal View History

2016-02-13 17:06:36 -06:00
#!/usr/bin/python
import keys
import logging
2016-02-13 17:06:36 -06:00
from vk import API, AuthSession, Session
log = logging.getLogger("vkSessionHandler")
2016-02-13 17:06:36 -06:00
class vkObject(object):
def __init__(self):
self.api_key = keys.keyring.get_api_key()
2018-01-14 07:18:00 -06:00
self.api_version = 5.69
log.debug("Created vkSession using VK API Version %s" % (self.api_version,))
2016-02-13 17:06:36 -06:00
def login(self, user, password):
log.debug("Logging in vk using user/password authentication")
2016-02-13 17:06:36 -06:00
s = AuthSession(app_id=self.api_key, user_login=user, user_password=password, scope="wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats")
self.client = API(s, v=self.api_version)
log.debug("Getting tokens for 24 hours...")
2016-02-13 17:06:36 -06:00
self.client.account.getProfileInfo()
def login_access_token(self, token):
log.debug("Logging in VK using stored tokens...")
2016-02-13 17:06:36 -06:00
s = Session(access_token=token)
self.client = API(s, v=self.api_version)
return self.client.account.getProfileInfo()