Java 使用td api获得前200次聊天
我正在使用TdApi获得前200个聊天记录,但我无法获得,我只获得前100个聊天记录。这里是我的代码,我试图获得200次聊天,但没有成功 甚至我也在网上阅读了文档 按正确顺序返回聊天列表,聊天按(顺序,聊天ID)降序排序。例如,要从一开始就获取聊天列表,offsetOrder应该等于2^63-1 就连我也试过:Java 使用td api获得前200次聊天,java,android,api,telegram,Java,Android,Api,Telegram,我正在使用TdApi获得前200个聊天记录,但我无法获得,我只获得前100个聊天记录。这里是我的代码,我试图获得200次聊天,但没有成功 甚至我也在网上阅读了文档 按正确顺序返回聊天列表,聊天按(顺序,聊天ID)降序排序。例如,要从一开始就获取聊天列表,offsetOrder应该等于2^63-1 就连我也试过: TdApi.GetChats getchats1 = new TdApi.GetChats(Long.MAX_VALUE, 0, 100); TG.getClientInstance()
TdApi.GetChats getchats1 = new TdApi.GetChats(Long.MAX_VALUE, 0, 100);
TG.getClientInstance().send(getchats1, new Client.ResultHandler() {
@Override
public void onResult(TdApi.TLObject object) {
TdApi.Chats chat = (TdApi.Chats) object;
final TdApi.Chat[] chats2 = chat.chats;
Log.e("OkHttp hey", "2 " + chats2.length + "");
Log.e("OkHttp hey", "2 " + chats2[0].title + "");
TdApi.GetChats getChats2 = new TdApi.GetChats(0, chats2[99].id, 100);
TG.getClientInstance().send(getChats2, new Client.ResultHandler() {
@Override
public void onResult(TdApi.TLObject object) {
TdApi.Chats chat = (TdApi.Chats) object;
final TdApi.Chat[] chats3 = chat.chats;
Log.e("OkHttp hey", "3 " + chats3.length + "");
Log.e("OkHttp hey", "2 " + chats3[0].title + "");
});
});
或者这个:
TdApi.GetChats getchats1 = new TdApi.GetChats(Long.MAX_VALUE, 0, 100);
TG.getClientInstance().send(getchats1, new Client.ResultHandler() {
@Override
public void onResult(TdApi.TLObject object) {
TdApi.Chats chat = (TdApi.Chats) object;
final TdApi.Chat[] chats2 = chat.chats;
Log.e("OkHttp hey", "2 " + chats2.length + "");
Log.e("OkHttp hey", "2 " + chats2[0].title + "");
TdApi.GetChats getChats2 = new TdApi.GetChats(Long.MAX_VALUE-100, 0, 100);
TG.getClientInstance().send(getChats2, new Client.ResultHandler() {
@Override
public void onResult(TdApi.TLObject object) {
TdApi.Chats chat = (TdApi.Chats) object;
final TdApi.Chat[] chats3 = chat.chats;
Log.e("OkHttp hey", "3 " + chats3.length + "");
Log.e("OkHttp hey", "2 " + chats3[0].title + "");
});
});
我举了一个例子:
对于获取所有聊天,我使用以下代码:
变量
//...
int64_t offset_order_ = std::numeric_limits<int64_t>::max();
int64_t offset_chat_id_ = 0;
//...
/。。。
int64_t offset_order_=std::numeric_limits::max();
int64\u t offset\u chat\u id=0;
//...
在更新聊天功能中
//for get next 100
if (chats->chat_ids_.size() > 0) {
auto last_chat_id = chats->chat_ids_[chats->chat_ids_.size() - 1];
send_query(td_api::make_object<td_api::getChat>(last_chat_id), [this](Object o){
if (o->get_id() == td_api::error::ID) {
return;
}
auto chat = td::move_tl_object_as<td_api::chat>(o);
offset_order_ = chat->order_;
offset_chat_id_ = chat->id_;
update_chats_ = true;
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
});
}
if (update_chats_) {
send_query(td_api::make_object<td_api::getChats>(offset_order_, offset_chat_id_, 100),
std::bind(&TgClient::update_chats, this, std::placeholders::_1));
update_chats_ = false;
}
//获取下一个100
如果(聊天->聊天\u id\u.size()>0){
自动上次聊天id=chats->chat\u id[聊天->聊天id\u.size()-1];
发送查询(td\U api::生成对象(最后一个聊天id),[this](对象o){
如果(o->get_id()==td_api::error::id){
返回;
}
自动聊天=td::移动对象作为(o);
偏移量\订单\聊天->订单;
offset\u chat\u id\u=chat->id;
更新_chats_=true;
//std::this_线程::sleep_for(std::chrono::毫秒(1000));
});
}
循环内功能
//for get next 100
if (chats->chat_ids_.size() > 0) {
auto last_chat_id = chats->chat_ids_[chats->chat_ids_.size() - 1];
send_query(td_api::make_object<td_api::getChat>(last_chat_id), [this](Object o){
if (o->get_id() == td_api::error::ID) {
return;
}
auto chat = td::move_tl_object_as<td_api::chat>(o);
offset_order_ = chat->order_;
offset_chat_id_ = chat->id_;
update_chats_ = true;
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
});
}
if (update_chats_) {
send_query(td_api::make_object<td_api::getChats>(offset_order_, offset_chat_id_, 100),
std::bind(&TgClient::update_chats, this, std::placeholders::_1));
update_chats_ = false;
}
if(更新聊天){
发送查询(td_api::生成对象(偏移量、顺序、偏移量、聊天量、id、100),
std::bind(&TgClient::update_chats,this,std::placeholders::_1));
更新_chats_=false;
}