T
T
TTXSTM2022-03-23 22:29:49
Java
TTXSTM, 2022-03-23 22:29:49

DonationAlerts API - How to get Code, Token via link?

Hi, I'm having this problem connecting to the DonationAlert API
. At first, DonationAlerts outputs 'Unauthenticated.' then I read that you need to get the code, token using the link:

String API_KEY = "API_TOKEN";
        String  APP_ID = "APP_ID";
        String REDIRECT_URI = "REDIRECT_URI";
        String SCOPE = "oauth-donation-index";
 
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://www.donationalerts.com/oauth/authorize?client_id="+ APP_ID + "&redirect_uri=" + REDIRECT_URI + "&response_type=code&scope=" + SCOPE + "oauth-donation-index"))
                .method("GET", HttpRequest.BodyPublishers.noBody())
                .build();
        HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
        System.out.println(response);

I tried to do this, but the link with "code" does not generate.

When you click on the link, it displays the following text:
{"error":"invalid_client","error_description":"Client authentication failed","message":"Client authentication failed"}


I also tried to get a link using .header() but the situation does not change

Tell me how can I get code, token DonationAlerts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TTXSTM, 2022-03-24
@TTXSTM

First you need to collect the link and open it through the browser

Desktop.getDesktop().browse(new URI("https://www.donationalerts.com/oauth/authorize?" + "client_id=" + APP_ID + "&redirect_uri=" + REDIRECT_URI + "&response_type=token" + "&scope=" + SCOPE));

Then
you will be redirected to the REDIRECT_URI where you can get a token from the link
. Further authorization as from the documentation:
HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://www.donationalerts.com/api/v1/alerts/donations"))
                .header("Authorization", "Bearer  " + API)
                .method("GET", HttpRequest.BodyPublishers.noBody())
                .build();
        HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());

O
Orkhan, 2022-03-24
Hasanly @azerphoenix

Good afternoon.
There is documentation here where you can read in detail:
https://www.donationalerts.com/apidoc
Read from: "1 - Application Registration" to "3 - Getting Access Token"
In your code, you did not define the values ​​of these variables:

String API_KEY = "API_TOKEN";
        String  APP_ID = "APP_ID";
        String REDIRECT_URI = "REDIRECT_URI";
        String SCOPE = "oauth-donation-index";

After reading the above chapters, you will understand what needs to be entered there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question