【发布时间】:2017-02-26 05:36:37
【问题描述】:
我正在我的 java 应用程序中处理 Telegram api。 我需要对我的电报帐户进行身份验证和授权,并获取我的特定组的消息列表。 为此,我首先从电报网站获得了api_id、api_hash 和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 测试了url,这返回了404 Not Found html 内容。 java中调用电报api方法的正确方法是什么?
更新:
我尝试使用 java socket 发送 TCP 发布请求,但这返回给我 404 not found。
【问题讨论】:
-
您是否查看了使用 API 的库?例如。 github.com/ex3ndr/telegram-api ...
-
@Fildor 如果可能,我不想使用第 3 方库。我想使用 main java 方法来做到这一点。
-
不,不使用它。看看,那里是怎么做的……
-
https://149.154.167.40:443- 你确定这是一个有效的 IP/端口吗? -
@Fildor Telegram 网站向我提供了该 IP 地址。