Answer the question
In order to leave comments, you need to log in
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();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question