使用Telegram API进行Java桌面应用程序? [英] Using Telegram API for Java Desktop App?

查看:1071
本文介绍了使用Telegram API进行Java桌面应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是Java编程的新手,但我从来没有使用过外部库。现在我想开发一个桌面客户端的电报开源消息传递平台,而当我遇到API用法。



有关Telegram API的相关文档,请参阅 https ://core.telegram.org/api ,我已经从github下载了mtproto,telegram-api和tl-core,并通过使用gradle从源代码编译了我自己的库jar。此外,我已经编写了一个小型应用程序,用户点击一个按钮,并且被允许输入他的电话号码,我正在使用Java-swing-Libraries和一个ActionListener。



现在应该检查用户输入的电话号码是否已经注册,auth.checkPhone方法似乎有能力。但是如何在我的eclipse项目中引用它呢?我没有看到任何方法checkPhone在任何类!我应该怎么办?



请帮助我,我不能帮助自己,我拼命困在我的项目中。
Lukas

解决方案



/ div>

本质上,您必须填写 ex3ndr / ...中GitHub上给出的代码中的空白, telegram-api 信息库。如果您已经在Eclipse项目的Java构建路径中创建了您创建的库Jar文件和 tl-api-v12.jar 文件,那么请查看 RPC Calls 部分的README和



首先,您需要使用设置 AppInfo 对象API凭据,那么您还必须创建一些新的类来实现 AbsApiState ApiCallback 接口。一旦这些可用,您可以创建 TelegramApi 对象,并按如下方式对电报服务进行RPC调用:在这种情况下,请使用建议的 auth.checkPhone 方法:

  // TODO设置AbsApiState,AppInfo和ApiCallback对象
TelegramApi api = new TelegramApi state,appInfo,apiCallback);

//创建请求
String phoneNumber =1234567890;
TLRequestAuthCheckPhone checkPhone = new TLRequestAuthCheckPhone(phoneNumber);

//同步调用服务
TLCheckedPhone checkedPhone = api.doRpcCall(checkPhone);
boolean invite = checkedPhone.getPhoneInvited();
boolean registered = checkedPhone.getPhoneRegistered();
// TODO进程响应进一步

TelegramApi object表示您与远程服务的连接,这是API的请求响应风格。 RPC调用是通过 doRpcCall 方法进行的,该方法从 org.telegram.api.requests 包中获取一个请求对象(示例中的 TLRequestAuthCheckPhone 类型)填入适当的参数。然后返回响应对象( TLCheckedPhone ),结果可用。



在异步调用方法立即返回,结果可用时执行 onResult 回调方法:

  //异步调用服务
api.doRpcCall(checkPhone,new RpcCallbackEx< TLCheckedPhone>(){
public void onConfirmed(){}
public void onResult TLCheckedPhone结果){
boolean invite = checkedPhone.getPhoneInvited();
boolean registered = checkedPhone.getPhoneRegistered();
// TODO进程响应进一步
}
public void onError(int errorCode,String message){}
});


I am not that new to Java Programming, but I have never worked with external libraries etc. Now I want to develop a desktop client for the "Telegram" open-source messaging platform, and I'm stuck when it comes to API-Usage.

There is pretty much documentation about the Telegram API, found at https://core.telegram.org/api, and I've already downloaded mtproto, telegram-api and tl-core from github, and compiled my own library jar from source by using gradle. As well, I've already written a small application, where the user clicks a button and is promted to enter his phone number, I'm using the Java-swing-Libraries and an ActionListener for this.

The phone number entered by the user should now be checked if it is already registered, the auth.checkPhone method seems to be capable for that. But how can I refer to it within my eclipse project? I don't see any method "checkPhone" in any of the classes! What should I do?

Please help me, I can't help myself and I am desperately stuck in my project. Even a small hint would help.

Thanks in Advance, Lukas

解决方案

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.jarfile 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) { }
});

这篇关于使用Telegram API进行Java桌面应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆