📜 ⬆️ ⬇️

Limit Messages API VK - what to do

How it all began...


On February 2, I came across an interesting article: closing api for messages . My first thought was: "damn, how now to hack people, eh?". But then I became thoughtful: probably my bot on the long-field would stop working, and in general, this is not cool ...

But on February 15th, the api was still working, and I thought that it was again promised and not fulfilled (for example, as his transition to a public company).

But on February 20th, when getting a token through the vk_api library in python, an error popped up that the application did not have access to the messages.
')
And then I thought ...

I really didn’t want to cut down my chat bots on the long-field and I began to look for workarounds.

How to be?


The easiest way is to obey and turn off the bot, but I'm still a hacker)

First, it turned out that tokens received before the api closes still have access to messages.

Secondly, use api from here : that is, log in with cookies and send post requests here with about these parameters:

Options
act: a_run_method
al: 1
hash: hash derived from page
method: messages.getConversations
param_count: 20
param_extended: 0
param_filter: all
param_offset: 0
param_v: 5.92


The code to receive messages in python:

Code
import requests,lxml.html,re,json class invalid_password(Exception): def __init__(self, value):self.value = value def __str__(self):return repr(self.value) class not_valid_method(Exception): def __init__(self, value):self.value = value def __str__(self):return repr(self.value) class messages(object): def __init__(this,login,password): this.login = login this.password = password this.hashes = {} this.auth() def auth(this): headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language':'ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3', 'Accept-Encoding':'gzip, deflate', 'Connection':'keep-alive', 'DNT':'1'} this.session = requests.session() data = this.session.get('https://vk.com/', headers=headers) page = lxml.html.fromstring(data.content) form = page.forms[0] form.fields['email'] = this.login form.fields['pass'] = this.password response = this.session.post(form.action, data=form.form_values()) if "onLoginDone" not in response.text: raise invalid_password(" !") return def method(this,method,v=5.87,**params): if method not in this.hashes: this._get_hash(method) data = {'act': 'a_run_method','al': 1, 'hash': this.hashes[method], 'method': method, 'param_v':v} for i in params: data["param_"+i] = params[i] answer = this.session.post('https://vk.com/dev',data=data) return json.loads(re.findall("<!>(\{.+)",answer.text)[-1]) def _get_hash(this,method): html = this.session.get('https://vk.com/dev/'+method) hash_0 = re.findall('onclick="Dev.methodRun\(\'(.+?)\', this\);',html.text) if len(hash_0)==0: raise not_valid_method("method is not valid") this.hashes[method] = hash_0[0] 


Example of use:

 a = messages('login','password') messages_user = a.method("messages.getConversations",count=1) 

PS Who cares, here are my bots:

1 ) a bot for downloading music from VK
2 ) bot determines the id of any sticker VK

PPS The author of this article does not bear any responsibility for the entire written text above: the article above is created ONLY with educational purposes.

Source: https://habr.com/ru/post/446172/


All Articles