Telegram 机器人 API 响应 403 Forbidden - 向机器人发送直接消息时

发布于 2025-01-19 19:46:40 字数 1080 浏览 3 评论 0原文

$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";

          $data = [
              'chat_id' => '5232750517',
              'text' => 'Hello World'
          ];
          $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .
                                         http_build_query($data) );

错误信息

无法打开流:HTTP 请求失败! HTTP/1.1 403 禁止

然后我遵循这个解决方案 - Telegram bots API 响应 403 Forbidden

我的机器人用户名是@test247_bot 并将代码更改为:

$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";

  $data = [
      'chat_id' => '5232750517',
      'text' => 'Hello World'
  ];
  $response = file_get_contents("https://api.telegram.org/@test247_bot$apiToken/sendMessage?" .
                                 http_build_query($data) );

但也没有工作,错误信息

无法打开流:HTTP 请求失败! HTTP/1.1 404

请帮忙

$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";

          $data = [
              'chat_id' => '5232750517',
              'text' => 'Hello World'
          ];
          $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .
                                         http_build_query($data) );

The error message

Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

Then I am followed this solution - Telegram bots API responds 403 Forbidden

My bot username is @test247_bot and change the code to:

$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";

  $data = [
      'chat_id' => '5232750517',
      'text' => 'Hello World'
  ];
  $response = file_get_contents("https://api.telegram.org/@test247_bot$apiToken/sendMessage?" .
                                 http_build_query($data) );

But also did not work, the error message

Failed to open stream: HTTP request failed! HTTP/1.1 404

Please help

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

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

发布评论

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

评论(1

初见 2025-01-26 19:46:40

这不是构建URL的正确方法。

删除机器人的用户名。它只是“ bot”,然后是API令牌。

尝试:

file_get_contents("https://api.telegram.org/bot5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U/sendMessage?" .http_build_query($data) );

That's not the correct way to build your URL.

Remove your bot's username. It is simply "bot" followed by api token instead.

Try:

file_get_contents("https://api.telegram.org/bot5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U/sendMessage?" .http_build_query($data) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文