U
U
un_def2013-08-18 17:19:15
Python
un_def, 2013-08-18 17:19:15

Python, authorization on vk.com?

There is a script that receives data from vk.com/al_friends.php . It has been empirically established that only remixsid cookies are needed. I'm trying to get instructions from the Internet (requests is used):

auth_params = {'act': 'login', 'email': 'мыло', 'pass': 'пароль'}
r = requests.get('http://login.vk.com', params=auth_params)
# на данном этапе всё хорошо, возвращается страница пользователя, как будто авторизовались

# далее надо получить параметр __q_hash. Его (по мануалу) вытягиваем со страницы:
parse_hash = re.search('hash=([a-z0-9]+)', r.text)
hash = parse_hash.group(1)
# единственное место, где встречается hash= в коде страницы — ссылка «выйти» (https://login.vk.com/?act=logout&hash=…)

# теперь нужно сделать запрос к vk.com/login.php, используя полученный хэш:
auth_params = {'act': 'slogin', 'role': 'fast', 'redirect': '1', 'to': '', 's': '1', '__q_hash': hash}
r = requests.get('http://vk.com/login.php', params=auth_params)
# а вот теперь облом, получаем страницу с формой авторизации. Хотя по мануалу мы должны получить из неё remixsid (опять же, регэкспом из кода страницы)

Tried with user-agent ('User-Agent': 'Mozilla/5.0' - redirects to mobile version) and without (gives full version).
Actually, the question is - what's wrong? Either I misunderstood, or the authorization algorithm was changed, and now you need to get __q_hash in a different way.
Suggestions for an alternative way to get remixsid are also welcome (do not suggest copying from the browser yourself, I want complete autonomy :-)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
U
un_def, 2013-08-18
@un_def

Of course there is - vk.com/dev/friends.get
Moreover, this method does not require an access-token

This is what I missed, it turns out! :-) Through the API, it's elementary, in one line, you don't need to parse. Thanks Tsyganov_Ivan .

D
dimka665, 2014-04-03
@dimka665

I will advertise my module for accessing the vk.com API: https://github.com/dimka665/vk
Authorization has been implemented. Works on Python2.7, Python3.3

S
Stepan, 2013-08-18
@L3n1n

Parsing is more expensive than using API. Why are you not satisfied with the API request?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question