使用电报API的Java桌面应用程序? [英] Using Telegram API for Java Desktop App?

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

问题描述

我不认为新的Java编程,但我从来没有与外部库工作等。现在我想开发一个桌面客户端的电报开源短信平台,我被卡住,当涉及到API的用法。

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.

有是关于电报的API,在 https://core.telegram.org/api,我已经下载mtproto,电报的API和TL-核心从GitHub,并通过编制的gradle从源代码我自己的图书馆罐子。同时,我已经写了一个小程序,当用户点击一个按钮,并promted进入他的电话号码,我使用的是Java的摆动库,为此一个ActionListener。

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.

由用户输入的电话号码,现在应该检查它是否已经被注册,则auth.checkPhone方法似乎能够为该。但我怎么可以参考它在我的Eclipse项目中?我没有看到任何类的任何方法checkPhone!我应该怎么办?

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

推荐答案

从本质上讲,你将不得不在的 ex3ndr /电报-API 库。如果你有库Jar文件你建立你的Eclipse项目的Java构建路径上的 TL-API v12.jar 文件,然后看的RPC调用自述部分以及

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

首先,你需要建立一个了AppInfo 对象使用 API证书,那么你也必须创建实现了 AbsApiState ApiCallback 接口了一些新的类。一旦这些都可以,你可以创建 TelegramApi 对象并发出RPC调用电报服务如下:在这种情况下使用建议 auth.checkPhone 方法:

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

TelegramApi 对象重新presents远程服务,这是API的请求响应式的连接。 RPC调用是通过取得 doRpcCall 方法,这需要从 org.telegram.api.requests 封装请求对象(本例中的 TLRequestAuthCheckPhone 型)填充在具有适当的参数。响应对象( TLCheckedPhone 以上),然后用返回结果可用时。

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.

在异步调用该方法立即返回,当结果可用执行 onResult 回调方法的情况下:

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

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

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