我试图将电报数据库库用于java (tdlib或tdapi),但是当我通过SearchPublicChat获得通道的chatId并试图获取消息或查看消息时,我会得到一个错误。
Error{code=6 message= Chat not found}
我不明白为什么我收到上面的chatId,为什么当我把它传递给另一个方法时,我得到了那个错误,请帮助我解决这个问题和那个库。谢谢。
发布于 2016-12-17 15:41:06
从聊天中获取最后15条消息的示例
String username = "any_chat_public_link";
TdApi.SearchPublicChat searchPublicChat=new TdApi.SearchPublicChat(username);
TG.getClientInstance().send(searchPublicChat, new Client.ResultHandler() {
@Override
public void onResult(TdApi.TLObject object) {
TdApi.Chat chat = (TdApi.Chat) object;
TdApi.Message topMessage = chat.topMessage;
long chatId = chat.id;
TdApi.GetChatHistory getChatHistory = new TdApi.GetChatHistory(chatId, topMessage.id, 0, 15);
TG.getClientInstance().send(getChatHistory, new Client.ResultHandler() {
@Override
public void onResult(TdApi.TLObject object) {
TdApi.Messages messages = (TdApi.Messages) object;
}
});
}
});发布于 2016-12-16 19:56:26
在请求id聊天之前,TdLib必须知道当前会话中的此聊天。你需要通过@mention_link搜索这个聊天,如果它是公开的,或者得到整个聊天列表。此外,如果在此聊天中发生了某些操作(比如聊天中的新消息,聊天更新.),则库将了解chat的情况。
这也适用于消息、用户等。只有当TdLib知道这个实体时,您才可以通过id请求它。
发布于 2022-05-16 11:02:57
在接收消息历史记录之前,您需要通过发送TdApi.JoinChat订阅聊天。程序如下:
1) TdApi.SearchPublicChat
2) TdApi.JoinChat
3) TdApi.GetChatHistoryTdApi.GetChatHistory需要最后一条聊天消息的id。它可以用TdApi.GetChat方法得到。我用的是tdlib/示例。有关聊天的信息由getMainChatList方法自动更新,然后可以从chats.get(chatId)获得。
https://stackoverflow.com/questions/41189849
复制相似问题