Essentially you will have to fill out the blanks in the code given on GitHub in the ex3ndr/telegram-api repository. If you've got the library Jar file you built and the tl-api-v12.jar
file on your Eclipse project's Java build path, then look at the RPC Calls section of the README and
First you need to set up an AppInfo
object with your API credentials, then you will also have to create some new classes that implement the AbsApiState
and ApiCallback
interfaces. Once these are available, you can create the TelegramApi
object and make an RPC call to the Telegram service as follows; in this case using the suggested auth.checkPhone
method:
// TODO set up AbsApiState, AppInfo and ApiCallback objects
TelegramApi api = new TelegramApi(state, appInfo, apiCallback);
// Create request
String phoneNumber = "1234567890";
TLRequestAuthCheckPhone checkPhone = new TLRequestAuthCheckPhone(phoneNumber);
// Call service synchronously
TLCheckedPhone checkedPhone = api.doRpcCall(checkPhone);
boolean invited = checkedPhone.getPhoneInvited();
boolean registered = checkedPhone.getPhoneRegistered();
// TODO process response further
The TelegramApi
object represents your connection to the remote service, which is a request response style of API. RPC calls are made via the doRpcCall
method, which takes a request object from the org.telegram.api.requests
package (the TLRequestAuthCheckPhone
type in the example) filled in with the appropriate parameters. A response object (TLCheckedPhone
above) is then returned with the result when it is available.
In the case of an asynchronous call the method returns immediately, and the onResult
callback method is executed when the result is available:
// Call service aynchronously
api.doRpcCall(checkPhone, new RpcCallbackEx<TLCheckedPhone>() {
public void onConfirmed() { }
public void onResult(TLCheckedPhone result) {
boolean invited = checkedPhone.getPhoneInvited();
boolean registered = checkedPhone.getPhoneRegistered();
// TODO process response further
}
public void onError(int errorCode, String message) { }
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…