Answer the question
In order to leave comments, you need to log in
VK login using Kotlin/Java?
In this post (which, unfortunately, is already in 2012), the author managed to write a function that itself received an Access Token.
Now we need to do the same.
The function on Kotlin that is available (full analogue from the post):
//Здесь добавлено, дабы не было ошибки при работе с cookie
val globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()
val httpClient = HttpClientBuilder.create().setDefaultRequestConfig(globalConfig).build()
var post = HttpPost(
"http://oauth.vk.com/authorize?" +
"client_id=" + id +
"&scope=" + "wall,photos" +
"&redirect_uri=" + "https://oauth.vk.com/blank.html" +
"&display=" + "popup" +
"&response_type=" + "token"
)
var response = httpClient.execute(post)
post.abort()
// Тут ошибка NullPointerException
var headerLocation = response.getFirstHeader("location").value
val uri = URI(headerLocation)
val ip_h = uri.query.split("&")[2].split("=")[1]
val to_h = uri.query.split("&")[4].split("=")[1]
post = HttpPost(
"https://login.vk.com/?act=login&soft=1"+
"&q=1"+
"&ip_h="+ip_h+
"&from_host=oauth.vk.com"+
"&to="+to_h+
"&expire=0"+
"&email="+ login +
"&pass="+ pass
)
response = httpClient.execute(post)
post.abort()
headerLocation = response.getFirstHeader("location").value
post = HttpPost(headerLocation)
response = httpClient.execute(post)
post.abort()
headerLocation = response.getFirstHeader("location").value
httpClient.close()
return headerLocation.split("#")[1].split("&")[0].split("=")[1]
Answer the question
In order to leave comments, you need to log in
There are already ready-made solutions like Spring Social VKontakte .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question