Advertisement
stuppid_bot

Клиент для контакта на Питоне

Aug 17th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import urllib, json
  3.  
  4. class VKClient:
  5.     def __init__(self, client_id, client_secret, scope=''):
  6.         self.client_id = client_id
  7.         self.client_secret = client_secret
  8.         self.scope = scope
  9.         self.auth = {}
  10.  
  11.     def login(self, username, password, captcha_sid='', captcha_key=''):
  12.         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
  13.         f = urllib.urlopen(s)
  14.         response = f.read()
  15.         self.auth = json.loads(response)
  16.  
  17.     def call(self, method, params={}):
  18.         """see http://vk.com/dev/methods"""
  19.         url = 'https://api.vk.com/method/' + method
  20.         body = ''
  21.         if len(params):
  22.             body = urllib.urlencode(params) + '&'
  23.         body += 'access_token=' + self.auth['access_token']
  24.         f = urllib.urlopen(url, body)
  25.         response = f.read()
  26.         return json.loads(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement