4

I'm attempting to create a small program that can demonstrate some features of the Telegram API. I wish to be able to register and authenticate users via SMS. According to the user authorization guide, I need to invoke the auth.sendCode RPC. However, the codebase is inadequately documented and is proving hard to get into.

How do I send the auth.sendCode remote procedure call in Telegram? Please provide a code snippet which shows everything starting from set up and initialization.

brain56
  • 2,659
  • 9
  • 38
  • 70

1 Answers1

0

Try Like this...

TLSentCode sentCode;
    try {
        sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, 5, "your app id", "en"));
    } catch (RpcException e) {
        if (e.getErrorCode() == 303) {
            int destDC;
            if (e.getErrorTag().startsWith("NETWORK_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("NETWORK_MIGRATE_".length()));
            } else if (e.getErrorTag().startsWith("PHONE_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("PHONE_MIGRATE_".length()));
            } else if (e.getErrorTag().startsWith("USER_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("USER_MIGRATE_".length()));
            } else {
                throw e;
            }
            api.switchToDc(destDC);
            sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, 5, "youa app id", "en"));
        } else {
            throw e;
        }
    }
Kersy
  • 116
  • 5