英文:
How to get information about any user having only user_id in telegram bot in Java?
问题
I use Java and telegrambots library. Using the keyboardButtonRequestUser method, I can get the user_id of an outside user, but how to collect all the information about an outside user with only the user_id?
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
String massageText = update.getMessage().getText();
long chatId = update.getMessage().getChatId();
User user = update.getMessage().getFrom();
if (massageText.equals("/start")) {
System.out.println("OutsideUserId = 6165875618 --> ...????");
startCommandReceived(chatId, update.getMessage().getChat().getFirstName());
}
else {
sendMessage(chatId, "Sorry, command was not recognized");
}
}
else if (update.hasMessage()){
long chatId = update.getMessage().getChatId();
sendMessage(chatId, "UserShared --> "+ update.getMessage().getUserShared());
sendMessage(chatId, "ChatShared --> "+ update.getMessage().getChatShared());
sendMessage(chatId, "CurrentChatId --> "+chatId);
}
}
(Note: The code portion has been provided without translation as requested.)
英文:
I use Java and telegrambots library. Using the keyboardButtonRequestUser method, I can get the user_id of an outside user, but how to collect all the information about outside user with only the user_id?
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
String massageText = update.getMessage().getText();
long chatId = update.getMessage().getChatId();
User user = update.getMessage().getFrom();
if (massageText.equals("/start")) {
// UserShared --> UserShared(requestId=732633638, userId=6165875618)
System.out.println("OutsideUserId = 6165875618 --> " + "...????");
startCommandReceived(chatId, update.getMessage().getChat().getFirstName());
}
else {
sendMessage(chatId, "Sorry, command was not recognized");
}
}
else if (update.hasMessage()){
long chatId = update.getMessage().getChatId();
sendMessage(chatId, "UserShared --> "+ update.getMessage().getUserShared());
sendMessage(chatId, "ChatShared --> "+ update.getMessage().getChatShared());
sendMessage(chatId, "CurrentChatId --> "+chatId);
}
}
答案1
得分: 1
我不是100%确定,但我认为这是不可能的,因为我们只能在用户进入机器人时请求用户数据。有人对此持不同意见吗?
英文:
I'm not 100% sure, but in my opinion this is impossible because we can only request user data when he enters the robot. Anybody have a different opinion on this?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论