我使用java telegram api与windows intellij idea中的电报核心api进行通信。
https://github.com/ex3ndr/telegram-api
但该应用正面临超时错误AppInfo appinfo=new AppInfo(45687, "Myapp", "154", "587","en");
TLRequestAuthCheckPhone checkRequest = new TLRequestAuthCheckPhone("96521452365");
MyApiStorage state=new MyApiStorage();
TelegramApi api = new TelegramApi(state, appinfo, new ApiCallback()
{
public void onApiDies(TelegramApi api) {
// When auth key or user authorization dies
}
@Override
public void onUpdatesInvalidated(TelegramApi api) {
System.out.print("############################### onUpdatesInvalidated");
// When api engine expects that update sequence might be broken
}
@Override
public void onAuthCancelled(TelegramApi ta) {
System.out.print("############################### onAuthCancelled");
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void onUpdate(TLAbsUpdates updates) {
System.out.print("############################### onUpdate");
System.out.println("user Id ::::"+((TLUpdateShortMessage) updates).getFromId());
}
});
api.switchToDc(1);
TLConfig config = api.doRpcCall(new TLRequestHelpGetConfig());
System.out.print("############################### config" + config.getTestMode());
state.updateSettings(config);
api.doRpcCall(checkRequest, new RpcCallbackEx<TLCheckedPhone>() {
public void onConfirmed() {
System.out.print("############################### onConfirmed");
}
public void onResult(TLCheckedPhone result) {
boolean invited = result.getPhoneInvited();
boolean registered = result.getPhoneRegistered();
System.out.print("############################### onResult" + registered);
// TODO process response further
}
public void onError(int errorCode, String message) {
System.out.print("############################### onError" + message);
}
});
完整源代码:
insertImage
有人可以帮助我
答案 0 :(得分:2)
您的超时可能由于以下几个原因发生:
1.您正在使用
api.doRpcCall(new TLRequestHelpGetConfig());
在TelegramApi类中,这转换为
return this.doRpcCall(method, timeout, 0);
0代表DC。如果您的DC不同,您将超时
2.其他地方有人建议使用doRpcCallSide,它适用于某些人而不适用于其他人。原因是它转化为
return this.doRpcCall(method, 15000, this.primaryDc, true);
其中true代表authRequired。
3.如果您想在未经授权的情况下执行此操作,请使用
api.doRpcCallNonAuth