powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Авторизация вконтакте. Зайди !
3 сообщений из 3, страница 1 из 1
Авторизация вконтакте. Зайди !
    #38425188
stim644
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот щас ковыряюсь с этим, не могу получить токен :
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
     HttpPost post;
    HttpResponse response;
    HttpClient httpClient = new InsecureHttpClientFactory().buildHttpClient();
    // Делаем первый запрос
    post = new HttpPost("http://api.vkontakte.ru/oauth/authorize?" +
    "client_id="+appID+
    "&scope="+scope+
    "&redirect_uri="+redirectURI+
    "&display="+display+
    "&response_type="+responseType);
    response = httpClient.execute(post);
    post.abort();
    //Получаем редирект
    String HeaderLocation = response.getFirstHeader("location").getValue();
    URI RedirectUri = new URI(HeaderLocation);
    System.out.println("response="+response);
    System.out.println("RedirectUri="+RedirectUri);
    String ip_h= RedirectUri.getQuery().split("&")[2].split("=")[1];
    String to_h=RedirectUri.getQuery().split("&")[4].split("=")[1];
    System.out.println("ip_h=" + ip_h);
    System.out.println("to_h=" + to_h);
    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="+login+
    "&pass="+pass);
    response = httpClient.execute(post);
    post.abort();
    System.out.println("response="+response);
    HeaderLocation = response.getFirstHeader("location").getValue();
    post = new HttpPost(HeaderLocation);
    // Проходим по нему
    response = httpClient.execute(post);
    System.out.println("response="+response);
    HeaderLocation = response.getFirstHeader("location").getValue();
    // Проходим по нему
    post = new HttpPost(HeaderLocation);
    response = httpClient.execute(post);
    post.abort();
    // Теперь в след редиректе необходимый токен
    HeaderLocation = response.getFirstHeader("location").getValue();



Где в последнем ответе нет заголовка Location, где и должен содержатся токен.
Вопрос почему ?
Подскажите пожалуйста люди добрые =)
...
Рейтинг: 0 / 0
Авторизация вконтакте. Зайди !
    #38425219
забыл ник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
может потому что new InsecureHttpClientFactory() ?
...
Рейтинг: 0 / 0
Авторизация вконтакте. Зайди !
    #38425297
stim644
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Не... Забыл класс этот показать :

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
public class InsecureHttpClientFactory {
    
    DefaultHttpClient hc;
        
    public DefaultHttpClient buildHttpClient() throws NoSuchAlgorithmException,
                                                      KeyManagementException,
                                                      KeyStoreException,
                                                      UnrecoverableKeyException {
        hc = new DefaultHttpClient();
        //configureProxy();
        configureCookieStore();
        configureSSLHandling();
        return hc;
    }

    private void configureProxy() {
        HttpHost proxy = new HttpHost("proxy.example.org", 3182);
        hc.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }

    private void configureCookieStore() {
        CookieStore cStore = new BasicCookieStore();
        hc.setCookieStore(cStore);
    }

    private void configureSSLHandling() throws NoSuchAlgorithmException,
                                               KeyManagementException,
                                               KeyStoreException,
                                               UnrecoverableKeyException {
        Scheme http =
            new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
        SSLSocketFactory sf = buildSSLSocketFactory();
        Scheme https = new Scheme("https", 443, sf);
        SchemeRegistry sr = hc.getConnectionManager().getSchemeRegistry();
        sr.register(http);
        sr.register(https);
    }

    private SSLSocketFactory buildSSLSocketFactory() throws NoSuchAlgorithmException,
                                                            KeyManagementException,
                                                            KeyStoreException,
                                                            UnrecoverableKeyException {
        TrustStrategy ts = new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] x509Certificates,
                                     String s) throws CertificateException {
                return true; // heck yea!
            }
        };

        SSLSocketFactory sf = null;

        try {
            /* build socket factory with hostname verification turned off. */
            sf =
 new SSLSocketFactory(ts, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return sf;
    }

}



Еще варианты ? )
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Авторизация вконтакте. Зайди !
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]