T
T
TTXSTM2022-03-27 17:32:32
Java
TTXSTM, 2022-03-27 17:32:32

Centrifuge java - Why is Closing error: 3002 / {"reason":"invalid token","reconnect":false}?

Hello everyone, I have such a problem, I wrote the Centrifuge-java connection code as in the example: https://github.com/centrifugal/centrifuge-java

public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String TOKEN = " ";
        System.out.println("Введите токен: ");
//        TOKEN = in.nextLine();

        EventListener listener = new EventListener() {
            @Override
            public void onConnect(Client client, ConnectEvent event) {
                System.out.println("connected");
            }

            @Override
            public void onDisconnect(Client client, DisconnectEvent event) {
                System.out.printf("disconnected %s, reconnect %s%n", event.getReason(), event.getReconnect());
            }
        };

        SubscriptionEventListener subListener = new SubscriptionEventListener() {
            @Override
            public void onSubscribeSuccess(Subscription sub, SubscribeSuccessEvent event) {
                System.out.println("subscribed to " + sub.getChannel());
            }

            @Override
            public void onSubscribeError(Subscription sub, SubscribeErrorEvent event) {
                System.out.println("subscribe error " + sub.getChannel() + " " + event.getMessage());

            }

            @Override
            public void onPublish(Subscription sub, PublishEvent event) {
                String data = new String(event.getData(), UTF_8);
                System.out.println("message from " + sub.getChannel() + " " + data);
            }
        };

        Client client = new Client(
                "wss://centrifugo.donationalerts.com/connection/websocket?format=protobuf",
                new Options(),
                listener
        );

        client.setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI5Mjc1IiwianRpIjoiNTQyMmE1M2QxYzc0Y2JjZGE3M2M1ZTM3NzM3ZmY3N2M3NzlkNTUxMjZhNDAyODgyNzExZDZhNDM1ZDM1ZWQzYTIyZWRmYWZlZmZjMzQ0Y2MiLCJpYXQiOjE2NDgzOTA2NTIsIm5iZiI6MTY0ODM5MDY1MiwiZXhwIjoyMjc5NTQyNjUxLCJzdWIiOiIxOTkyNTcyIiwic2NvcGVzIjpbIm9hdXRoLWRvbmF0aW9uLWluZGV4Il19.LyzE8Xi36OQKsF5w5hMK1lxfjXxs6hlPYnQbEyik1nnbCQsaLjDXymR3iZLM_czbiBcvhTFCTVy_4UQ-UYV8Ow1VLvbdvHCjN-vbSjRq-9lhIj6vtY82cvylsGEibQx6pFVghxdQ75itx_jm0_fjHdwjb1kD3cacp-rdwZH4HpWRWljdNRsM2F0lFIsRS0wte03AXiLs3ty6DnJ0x1ApeWWSewMxRtrdYGFAyGeQPqTVuuUcABThTfSj2MmWBOig8N2ygEL9S4EeCOKUcqLGtq3z3kKtfy0K1DecpFnHY5r2w9gnQuRW1bQeqIPlfM8xk0ofk5eG-3cEUYGZw_3O-Ybu3v-WmE-DjI_v5xfHcVk-aS3-OfcRAvshx0-dWKeGORSMwDacGq2aGgIOpBMYnVwm_Rvxo8T9AZ8RoJm5GbgTcbSFlbWjkRub2C-qmpIy1y4lylufX-k6-tTtmw2fPgBzn2unnpUkhxLUPFp_eFUAyfofszKrFw6eJdgv4y_vthBfyEBT1mhJIozjb5BOBqwQ3l19R81LEShY3U5E19gRQ1OZYRsmyNSt_ArYjIE_rduyxMibIpT4nsuuViN6-Mt-Khh3mamgkXmp3rB3tBkG40GiNmZK16vAAv-vcKqyMYpjcpET3viwt6QZ_bCY4xJvhKRApRxZI9W4aD6Cr10");
        client.connect();

        Subscription sub;

        try{
            sub = client.newSubscription("alerts:donation_9275", subListener);
        }catch (DuplicateSubscriptionException e){
            e.printStackTrace();
            return;
        }
        sub.subscribe();
    }


It gives the following error to the console:
Введите токен: 
Closing : 3002 / {"reason":"invalid token","reconnect":false}
disconnected invalid token, reconnect false
Closing : 3002 / {"reason":"invalid token","reconnect":false}


Do not pay attention to enter the token, I planned to enter the token through the console so that there would be no problems with arranging the token


As I understand it, he believes that the token is not correct, I took the token from the Donation Alerts API documentation, and it was also indicated there that the token should be taken from the user's combined link:
Like this: https://www.donationalerts.com/oauth/authorize?cli...


However, as in the usual connection of the Donation Alerts API

Therefore, I cannot understand what I did wrong, please tell me.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question