R
R
rinatsakaev2015-11-25 15:25:38
Java
rinatsakaev, 2015-11-25 15:25:38

How to log in to VK in Java without a browser?

Good day, gentlemen.
I use HttpClient 4.5.1, I try to log in to VK by sending a post-request to login.vk.com/?act=login with parameters:
email
pass
ip_h
lg_h
Looks like this:

HttpPost httpPostVk= new HttpPost("http://login.vk.com/?act=login");
        List<NameValuePair> formparamsVk=new ArrayList<NameValuePair>();
        formparamsVk.add(new BasicNameValuePair("email","******"));
        formparamsVk.add(new BasicNameValuePair("pass","*******"));
       formparamsVk.add(new BasicNameValuePair("ip_h",getIp_h()));
        formparamsVk.add(new BasicNameValuePair("lg_h",getLg_h()));
        UrlEncodedFormEntity entity2 = new UrlEncodedFormEntity(formparamsVk, Consts.UTF_8);
        httpPostVk.setEntity(entity2);
        HttpResponse response = httpclient.execute(httpPostVk);
        Header[] headers= response.getAllHeaders();
        for (int i=0;i<headers.length;i++) System.out.print(headers[i]+"\r\n");

At the output I get:
Server: Apache
Date: Tue, 24 Nov 2015 14:13:59 GMT
Content-Type: text/html; charset=windows-1251
Connection: keep-alive
X-Powered-By: PHP/3.19062
Set-Cookie: remixlang=0; expires=Mon, 14 Nov 2016 17:40:33 GMT; path=/; domain=.vk.com
Pragma: no-cache
Cache-control: no-store
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Location: http://vk.com/login.php?&to=&s=0&m=1&email=

In theory, a redirect with a hash should be returned, but instead it turns out that the username or password is incorrect.
Apparently, I am not sending some additional parameter. What's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mark Doe, 2015-11-25
@rinatsakaev

https://oauth.vk.com/token?grant_type=password&client_id=2274003&client_secret=hHbZxrka2uZ6jB1inYsH&username=LOGIN&password=PASS

And you get an eternal trusted application token with all rights. Only shh..

O
OnYourLips, 2015-11-25
@OnYourLips

They don't do that.
To interact with VKontakte there is an API
https://vk.com/dev/main

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question