我在java应用程序中处理Telegram api。 我需要使用我的电报帐户进行身份验证和授权,并获取我的特定群组的消息列表。为此,我首先得到api_id
,api_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
。
答案 0 :(得分:1)
由于它是mproto协议,您必须遵守他们的规范 - https://core.telegram.org/mtproto
我建议您使用此项目,因为它有工作示例 - https://github.com/badoualy/kotlogram