Limit Messages API VK - what to do
- Tutorial
How it all began...
February 2, I came across an interesting article: closing the api for messages . My first thought was: “Damn, how now to crack people, huh?” But then I became thoughtful: maybe my bot on the longfield will stop working, and in general, it's not cool ...
But on February 15th the api was still working, and I thought that VK again promised and did not fulfill it (for example, as its transfer to a public company) .
But on February 20, when receiving a token through the vk_api library in python, an error began to pop up that the application does not have access to messages.
And then I thought ...
Cutting out my chat bots on the longfield did not really want to and I began to look for workarounds.
How to be
The easiest way is to obey and disable the bot, but I'm still a hacker)
First, it turned out that the tokens received BEFORE closing the api still have access to messages.
Secondly, use api from here : that is, log in to VK with cookies and send post-requests here with approximately the following parameters:
Parameters
act: a_run_method
al: 1
hash: hash obtained from the
method: messages.getConversations
param_count: 20
param_extended: 0
param_filter: all
param_offset: 0
param_v: 5.92 page
The code for receiving messages in python:
The 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('method is not valid")
this.hashes[method] = hash_0[0]
Usage example:
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 ) a bot that determines the id of any VK sticker
PPS The author of this article does not bear any responsibility for the entire text written above: the article above was created ONLY for cognitive purposes.