Answer the question
In order to leave comments, you need to log in
How to pass VKontakte authorization in Java?
I am writing a client for VKontakte in Java. You need to get a token using the username and password set by the user. There are no materials on Habré and Google on this topic. Please help with a piece of code.
Answer the question
In order to leave comments, you need to log in
First, you need to create a Standalone application through a special VK form.
Secondly, if there is an opportunity and desire, you can use some kind of WebView to guide the user through all sorts of windows like entering authorization and allowing access.
But if this method is not suitable, then you can simply parse the HTML, and send POST requests, and at the very end, tear out the token from the address bar. For an Android app, I replaced # with "?" and parsed the resulting query string:
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
HttpHost currentHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
currentUrl = currentUrl.replace("#", "?");
Uri uri=Uri.parse(currentUrl);
String access_token = uri.getQueryParameter("access_token");
long user_id = Long.valueOf(uri.getQueryParameter("user_id"));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question