简体   繁体   中英

How to get the Telegram bot username in Java?

我知道如何获取向我的机器人发送更新或消息的用户的用户名,但是如何在不求助于 BotFather 的情况下获取我的机器人的用户名和/或名称?

How can I get the username and/or name of my bot

The Telegram Bot API provides a getMe method that:

A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object .


So, if you'd send a request like:

api.telegram.org/bot<MY-BOT-TOKEN>/getMe

You'll get the following response:

{
    "ok": true,
    "result": {
        "id": 12346798,
        "is_bot": true,
        "first_name": "my_test_bot",
        "username": "my_test_bot",
        "can_join_groups": true,
        "can_read_all_group_messages": false,
        "supports_inline_queries": false
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM