如何求解电报API Java API错误404

发布于 2025-01-23 05:43:29 字数 1311 浏览 2 评论 0原文

需要在使用电报API时使用此错误

Error removing old webhook
at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:112)
.....
Caused by: Error deleting webhook: [404] Not Found

@Service
public class Test1Api {


    @Autowired
    public Test1Api(@Value("${bot.username:}") String botUserName, @Value("${bot.token:}") String botToken) {
        try {
            TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
            telegramBotsApi.registerBot(new Test1Bot(botUserName, botToken));
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
}

public class Test1Bot extends TelegramLongPollingBot {

private final String botUserName;
private final String botToken;

public Test1Bot(String botUserName, String botToken) {
    this.botUserName = botUserName;
    this.botToken = botToken;
}


@Override
public String getBotUsername() {
    return botUserName;
}

@Override
public String getBotToken() {
    return botToken;
}

@Override
public void onUpdateReceived(Update update) {
    System.out.println(update.getMessage().getText());
    System.out.println(update.getMessage().getFrom());
}

帮助 附加在这里 电报中的错误: 我该怎么办?

I need help with this error when working with Telegram API

Error removing old webhook
at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:112)
.....
Caused by: Error deleting webhook: [404] Not Found

I have created a bot with telegram,

Service class:

@Service
public class Test1Api {


    @Autowired
    public Test1Api(@Value("${bot.username:}") String botUserName, @Value("${bot.token:}") String botToken) {
        try {
            TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
            telegramBotsApi.registerBot(new Test1Bot(botUserName, botToken));
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
}

here is the bot class

public class Test1Bot extends TelegramLongPollingBot {

private final String botUserName;
private final String botToken;

public Test1Bot(String botUserName, String botToken) {
    this.botUserName = botUserName;
    this.botToken = botToken;
}


@Override
public String getBotUsername() {
    return botUserName;
}

@Override
public String getBotToken() {
    return botToken;
}

@Override
public void onUpdateReceived(Update update) {
    System.out.println(update.getMessage().getText());
    System.out.println(update.getMessage().getFrom());
}

When i try to run my code i have an error from telegram
attaching here
The error from telegram:
What can i do to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深陷 2025-01-30 05:43:29

确保您提供良好的令牌。
您可以通过手动请求Telegram Bot删除Webhook进行检查。
[post] https://api.telegram.org/bot.org/bot

好的,您应该得到回应:

{
“好”:是的,
“结果”:是的,
“描述”:“ Webhook已被删除”
}

然后,您可以确定您的令牌是正确的,但是您将其提供错误。
可以检查您的应用程序。

但是,如果您的响应不同(例如找不到) - 电报令牌存在问题。

Make sure you provide a good token.
You can check it by manually requesting your telegram bot to delete webhook.
[POST] https://api.telegram.org/bot<your_token>/deleteWebhook

If everything is alright you should get as a response:

{
"ok": true,
"result": true,
"description": "Webhook is already deleted"
}

Then you'll be sure that your token is correct but you're providing it wrong.
Maybe check your application.properties

However if your response is different (eg. Not Found) - there's problem with your telegram token.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文