我正在尝试获取电报机器人API中的所有chat_id
当我打电话
https://api.telegram.org/botmybot_token/getUpdates
我得到这个{"ok":true,"result":[]}
答案 0 :(得分:1)
You get empty updates because there were no messages (or other actions) from users.
To obtain user's chat_id
follow these steps:
Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/ links or username search to find your bot.
timeout=
because this is a long polling method (i.e. you will receive response only when there is a new incoming update or timeout is reached):
(timeout is) Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.
You can still receive updates without timeout
setting, but that's not the right way to read user interaction. Instead you can you just run long-polling (i.e. with timeout
setting) requests in a loop.
You can read more on getting infromation about user's chat_id
here:
https://stackoverflow.com/a/56093268/2315573