rubenlagus / TelegramApi

Java library to create Telegram Clients
MIT License
300 stars 108 forks source link

RpcException: PHONE_MIGRATE_2 #84

Closed DmitriyDmitruk closed 5 years ago

DmitriyDmitruk commented 5 years ago

Hi! I`m getting RpcException: PHONE_MIGRATE_2 for this string TLSentCode t_ = api.doRpcCallNonAuth(t2);

Please help me to deal with it! I am grateful for any help!

import java.io.IOException; import java.util.concurrent.TimeoutException; import java.util.logging.Level; import java.util.logging.Logger;

import org.telegram.api.TLConfig; import org.telegram.api.auth.TLCheckedPhone; import org.telegram.api.auth.TLSentCode; import org.telegram.api.engine.ApiCallback; import org.telegram.api.engine.AppInfo; import org.telegram.api.engine.RpcException; import org.telegram.api.engine.TelegramApi; import org.telegram.api.engine.storage.AbsApiState; import org.telegram.api.functions.auth.TLRequestAuthCheckPhone; import org.telegram.api.functions.auth.TLRequestAuthSendCode; import org.telegram.api.functions.help.TLRequestHelpGetConfig; import org.telegram.api.updates.TLAbsUpdates; import org.telegram.bot.kernel.engine.MemoryApiState;

public class Main {

private static final String PHONENUMBER ="38097291918";
private static final int APIKEY = 870890; // your api key
private static final String APIHASH = "3344146ca34e316563796c93b798a53"; // your api hash

public static void main(String[] args) throws RpcException {

    AbsApiState apiState = new MemoryApiState("test.log");
    TelegramApi api = new TelegramApi(apiState, new AppInfo(APIKEY, "desc", "test", "1", "en"), new ApiCallback() {

        @Override
        public void onAuthCancelled(TelegramApi api) {
            System.err.println("onAuthCancelled");
        }

        @Override
        public void onUpdatesInvalidated(TelegramApi api) {
            System.err.println("onUpdatesInvalidated");
        }

        @Override
        public void onUpdate(TLAbsUpdates updates) {
            System.err.println("onUpdate");
        }
    });
    try {
        final TLConfig config = api.doRpcCallNonAuth(new TLRequestHelpGetConfig());
        apiState.setPrimaryDc(config.getThisDc());
        apiState.updateSettings(config);
    } catch (TimeoutException e) {

    }
    new Thread(() -> {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
        }
        TLRequestAuthCheckPhone tl = new TLRequestAuthCheckPhone();
        tl.setPhoneNumber("380972991918");
        try {
            TLCheckedPhone t = api.doRpcCallNonAuth(tl);
            System.err.println(">>>>>>>>>>>>>>>>>>> IS HPONE REGISTERED " + t.isPhoneRegistered());
        } catch (RpcException ex) {
        } catch (TimeoutException ex) {
        }
    }).start();

    new Thread(() -> {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
        }
        TLRequestAuthSendCode t2 = new TLRequestAuthSendCode();
        t2.setPhoneNumber(PHONENUMBER);
        t2.setApiId(APIKEY);
        t2.setApiHash(APIHASH);
        try {
            TLSentCode t_ = api.doRpcCallNonAuth(t2);
            System.err.println(">>>>>>>>>>>>>>>>>>> IS HPONE REGISTERED " + t_.isPhoneRegistered());
            System.err.println(">>>>>>>>>>>>>>>>>>> OBJECT t_ " + t_);
        } catch (IOException ex) {
            System.err.println(">>>>>>>>>>>>>>>>>>> IOException: " + ex);
        } catch (TimeoutException ex) {
            System.err.println(">>>>>>>>>>>>>>>>>>> TimeoutException: " + ex);
        }

    }).start();
}

}