Skip to content

Phone code always expired #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
junjie870113 opened this issue Aug 26, 2018 · 0 comments
Open

Phone code always expired #78

junjie870113 opened this issue Aug 26, 2018 · 0 comments

Comments

@junjie870113
Copy link

I'm trying to do some test against this lib, although I can get the SMS code, the call to authSingIn always says that the SMS code expired.

the telegram client is deployed in Chicago(VPS node) while the phone is in China. I try to change the timezone to 'Asia/Shanghai' but still failed

can anyone help me?

TelegramApi#1001:<< #1 error #400 PHONE_CODE_EXPIRED in 202 ms
MTProto#1002#Scheduller:Forgetting message: #10
MTProto#1002:Response Iteration
TelegramApi#1001:auth.signIn#bcd51581
java.util.concurrent.ExecutionException: org.telegram.api.engine.RpcException: PHONE_CODE_EXPIRED

private <T extends TLObject> T callNonAuth(TLMethod<T> method) {
	T t = null;
	try {
	    t = telegramApi.doRpcCallNonAuth(method);
	} catch (RpcException e) {
	    if (e.getErrorCode() == 303) {
            try {
	            	int destDC = Integer.valueOf(e.getErrorTag().replaceAll("NETWORK_MIGRATE_", "").replaceAll("PHONE_MIGRATE_", "").replaceAll("USER_MIGRATE_", ""));
	            	System.out.println("switch to DC:" + destDC);
	            	telegramApi.switchToDc(destDC);
	            	t = telegramApi.doRpcCallNonAuth(method);
			} catch (Exception e2) {
				System.err.println(e2.getMessage());
			}
        } else
        		System.err.println(e.getMessage());
	} catch (TimeoutException e) {
		System.err.println(e.getMessage());
	}
	return t;
}

public void userAuthorization(String countryCode, String phoneNumber, int apiId, String apiHash) throws Exception {
	TLSentCode tlSentCode = this.callNonAuth(new TLRequestAuthSendCodeBuilder().phoneNumber(countryCode + phoneNumber).apiId(apiId).apiHash(apiHash).build());
	System.out.println("wait for sms...");
	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	System.out.println("Activation code:");
	String phoneCode = reader.readLine();
	System.out.println("phoneCode:" + phoneCode + " phoneCodeHash:" + tlSentCode.getPhoneCodeHash() + " type:" + tlSentCode.getType());
	TLAuthorization tlAuthorization = this.callNonAuth(new TLRequestAuthSignInBuilder().phoneNumber(phoneNumber).phoneCode(phoneCode)
						.phoneCodeHash(tlSentCode.getPhoneCodeHash()).build());
	TLUser user = (TLUser) tlAuthorization.getUser();
	System.out.println("access hash:" + user.getAccessHash() + " userName:" + user.getUserName());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant