Answer the question
In order to leave comments, you need to log in
Authorization standalone application vk on java
Good afternoon or evening!
The topic is pretty hackneyed, but I did not find specific solutions.
habrahabr.ru/post/144813
Here we have a good example:
HttpClient httpClient = new DefaultHttpClient();
// Делаем первый запрос
HttpPost post = new HttpPost("http://oauth.vk.com/authorize?" +
"client_id="+client_id+
"&scope="+scope+
"&redirect_uri="+redirect_uri+
"&display="+display+
"&response_type="+response_type);
HttpResponse response;
response = httpClient.execute(post);
post.abort();
//Получаем редирект
String HeaderLocation = response.getFirstHeader("location").getValue();
URI RedirectUri = new URI(HeaderLocation);
//Для запроса авторизации необходимо два параметра полученных в первом запросе
//ip_h и to_h
String ip_h= RedirectUri.getQuery().split("&")[2].split("=")[1];
String to_h=RedirectUri.getQuery().split("&")[4].split("=")[1];
// Делаем запрос авторизации
post = new 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="+email+
"&pass="+pass);
response = httpClient.execute(post);
post.abort();
// Получили редирект на подтверждение требований приложения
HeaderLocation = response.getFirstHeader("location").getValue();
post = new HttpPost(HeaderLocation);
// Проходим по нему
response = httpClient.execute(post);
post.abort();
// Теперь последний редирект на получение токена
HeaderLocation = response.getFirstHeader("location").getValue();
// Проходим по нему
post = new HttpPost(HeaderLocation);
response = httpClient.execute(post);
post.abort();
// Теперь в след редиректе необходимый токен
HeaderLocation = response.getFirstHeader("location").getValue();
// Просто спарсим его сплитами
access_token = HeaderLocation.split("#")[1].split("&")[0].split("=")[1];
Answer the question
In order to leave comments, you need to log in
The issue is resolved, look towards javaFX and the attached javaFXSceneBuilder for FXML files, there are all the necessary components, including WebViev.
There is a working example of authorization in java, google kate api, along with the library there is a working, beautiful and neat example of authorization, nothing has changed in it at all.
If I'm not mistaken, then kate api is for android and there are such elements as webview, I just saw this in the kate api example
https://github.com/thest1/Android-VKontakte-SDK
I don't have this in NetBeans.
Sorry if I missed something in kate api, but I didn’t even see any such code for authorization.
Do not scoff at VK like that.
You throw the usual WebView on the activity. Set him on
https://oauth.vk.com/authorize?client_id=111111111&scope=friends,notify,photos,photos,audio,video,docs,notes,pages,groups,offline&redirect_uri=https://oauth.vk.com/blank.html&display=mobile&v=5.5&response_type=token
&revoke=1
WebView wv = (WebView) this.findViewById(R.id.webView1);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
wv.setHorizontalScrollBarEnabled(false);
webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
wv.setWebViewClient(new VkWebViewClient());
wv.loadUrl("https://oauth.vk.com/authorize?client_id=111111&scope=friends,notify,photos,photos,audio,video,docs,notes,pages,groups,offline&redirect_uri=https://oauth.vk.com/blank.html&display=mobile&v=5.5&response_type=token&revoke=1");
public class VkWebViewClient extends WebViewClient {
public VkWebViewClient() {
// TODO Auto-generated constructor stub
}
@Override
public void onPageFinished(WebView view, String url)
{
Log.i("VkWebViewClient onPageFinished",url);
if (url.contains("oauth.vk.com/blank.html#")) {
if (url.contains("error")) {
// Error
}
else
{
String ahrore = url.substring(url.indexOf("#")+1);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question