Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import urllib, json
- class VKClient:
- def __init__(self, client_id, client_secret, scope=''):
- self.client_id = client_id
- self.client_secret = client_secret
- self.scope = scope
- self.auth = {}
- def login(self, username, password, captcha_sid='', captcha_key=''):
- s = 'https://oauth.vk.com/token?grant_type=password&client_id=' + self.client_id + '&client_secret=' + self.client_secret + '&scope=' + self.scope + '&username=' + urllib.quote(username) + '&password=' + urllib.quote(password) + '&captcha_sid=' + captcha_sid + '&captcha_key=' + captcha_key
- f = urllib.urlopen(s)
- response = f.read()
- self.auth = json.loads(response)
- def call(self, method, params={}):
- """see http://vk.com/dev/methods"""
- url = 'https://api.vk.com/method/' + method
- body = ''
- if len(params):
- body = urllib.urlencode(params) + '&'
- body += 'access_token=' + self.auth['access_token']
- f = urllib.urlopen(url, body)
- response = f.read()
- return json.loads(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement