L
L
los angels2015-11-17 14:15:23
Java
los angels, 2015-11-17 14:15:23

What is the error in getting the token?

I tried to get a token and just withdraw it, but for some reason it does not work. What could be wrong?

public class Token {
    private final String response_type;
    private String access_token;
    private final String client_id;

    public Token() {
        this.response_type = "token";
        this.client_id = "a42b1aed99284cb3a62f4d57f2392385";
    }
public void setConnection() throws IOException, URISyntaxException {
        //код получения token'a
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost post = new HttpPost("https://oauth.yandex.ru/authorize?" +
    "response_type="+response_type+
    "&client_id="+client_id);
    HttpResponse response;
    response = httpClient.execute(post);
    post.abort();
    String HeaderLocation = response.getFirstHeader("location").getValue();
    URI RedirectUri = new URI(HeaderLocation);
    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];
    System.out.println(access_token);
    }
    public static void main(String[] args) throws IOException, URISyntaxException, AWTException, InterruptedException, NoSuchAlgorithmException {
    Token yandexAPI = new Token();
    yandexAPI.setConnection();
    
    }
}

Compile error:
Exception in thread "main" org.apache.commons.logging.LogConfigurationException: No suitable Log implementation
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:918)
at org.apache. commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
at org.apache.commons.logging.impl.LogFactoryImpl. getInstance(LogFactoryImpl.java:310)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:686)
at org.apache.http.impl.client.CloseableHttpClient.(CloseableHttpClient.java:60)
at org. apache.http.impl.client.AbstractHttpClient.(AbstractHttpClient.java:271)
at org.apache.http.impl.client.DefaultHttpClient.(DefaultHttpClient.java:146)
at oblako.Token.setConnection(Token.java:41)
at oblako.Token.main(Token.java:64)
Java Result: 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2015-11-17
@aol-nnov

httpClient.execute(post);
post.abortion();

There is something I don't understand about this...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question