def vk_method(self, method, params = {}, post = False): # c57458088a0fe802c56a15e004c54f99a9cc56ac56a35e26d70d459c8ada8da # http://api.vk.com/api.php?v=3.0&api_id=1901988&method=getProfiles&format=json&rnd=343&uids=100172&fields=photo%2Csex&sid=10180116c4fd93480439bca47d636d6dd75fac30b851d4312e82ec3523&sig=5be698cf7fa09d30f58b941a4aea0e9b for key, param in params.iteritems(): try: params[key] = param.encode('utf-8') except: pass if post: url = "http://api.vk.com/api.php" # params['method'] = method params['api_id'] = self.app_id params['format'] = 'json' params['access_token'] = self.get_token() url = "https://api.vkontakte.ru/method/{method}".format(method = method) response = http_request(url, post = params, cookies_file = self.cookies_file) else: url = "https://api.vkontakte.ru/method/{method}?access_token={token}&{param_str}" url = url.format(method = method, token = self.get_token(), param_str = url_params(params)) response = http_request(url) try: json_data = json.loads(response) if json_data.has_key('response'): return json_data['response'] return json_data except json.decoder.JSONDecodeError: print "Json error: %s"%response return response
def get_auth_html(self, appid): params = { 'client_id': appid, 'scope': self.scope, 'redirect_uri': 'http://api.vkontakte.ru/blank.html', 'display': 'wap', 'response_type': 'token' } param_str = url_params(params) # url = "http://oauth.vk.com/authorize?%s"%param_str url = "http://api.vk.com/oauth/authorize?%s"%param_str html = http_request(url, cookies_file = self.cookies_file, read_headers = True) return html