正确的方式来调用电报api方法

时间:2016-10-17 09:35:18

标签: java telegram

我在java应用程序中处理Telegram api。 我需要使用我的电报帐户进行身份验证和授权,并获取我的特定群组的消息列表。为此,我首先得到api_idapi_hash和{{1}来自电报网站。其次,我尝试以这种方式使用MTProto servers方法授权我的帐户:

auth.sendCode

但这会让我... String url = "https://149.154.167.40:443/auth.sendCode"; HttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); httpPost.addHeader("Content-type", "application/x-www-form-urlencoded"); httpPost.addHeader("charset", "UTF-8"); List<NameValuePair> nameValuePairs = new ArrayList<>(); nameValuePairs.add(new BasicNameValuePair("phone_number", myPhoneNumber)); nameValuePairs.add(new BasicNameValuePair("sms_type", "5")); nameValuePairs.add(new BasicNameValuePair("api_id", api_id)); nameValuePairs.add(new BasicNameValuePair("api_hash", api_hash)); nameValuePairs.add(new BasicNameValuePair("lang_code", "en")); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); HttpResponse response = httpClient.execute(httpPost); ... 例外。我使用javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake代替http测试了网址,并返回了https个html内容。 在java中调用telegram api方法的正确方法是什么?

更新

我尝试使用404 Not Found发送TCP帖子请求,但这会返回java socket

1 个答案:

答案 0 :(得分:1)

由于它是mproto协议,您必须遵守他们的规范 - https://core.telegram.org/mtproto

我建议您使用此项目,因为它有工作示例 - https://github.com/badoualy/kotlogram

相关问题