我使用Java telegram API与Windows intellij idea中的telegram core API进行通信
https://github.com/ex3ndr/telegram-api
但应用程序面临超时错误行
TLConfig config = api.doRpcCall(new TLRequestHelpGetConfig());
完整的源代码:
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);
}
});
超时可能有以下几个原因:
1. 您正在使用
在TelegramApi类中,它被转换成
返回这个。dorpcall (method, timeout, 0);0表示DC。如果您的DC不同,您将超时
2. 在其他地方也有使用doRpcCallSide的建议,它对一些人有效,而对另一些人无效。原因是它被翻译成返回这个。dorpcall (method, 15000, this。primaryDc,真);之前其中true代表authRequired。
3.如果您想在未经授权的情况下执行此操作,则使用api.doRpcCallNonAuth