【问题标题】:always failed to send image using telegram API总是无法使用电报 API 发送图像
【发布时间】:2018-05-05 06:42:33
【问题描述】:

我想用电报 api 和 codeigniter 创建一个应用程序。当我尝试发送图像或其他文件时,我收到一些这样的错误:

消息:file_get_contents(''):打开流失败:HTTP 请求失败! HTTP/1.1 400 错误请求

我的控制器是这样的:

public function index()
{

this->tele = new telegramBot('token');

$path= base_url().'assets/maldini.png';
$info = $this->tele->sendPhoto('chati_id',$path);
print_r($info);
    $this->load->view('tes');
 }
}

如何解决这个问题?在此先感谢:)

【问题讨论】:

  • 带有额外 } 的语法错误以及“telegramBot”来自哪个库?
  • 最后一个“}”用于关闭主课先生,telegramBot 是这里的库:github.com/mgp25/Telegram-Bot-API

标签: php


【解决方案1】:

如果你使用这个库https://github.com/TelegramBot/Api,它的工作代码:

$chat_id = <chat_id>;
$token = <token>;
$bot = new \TelegramBot\Api\BotApi($token);

try {

    $bot->sendPhoto($chat_id, <file_id>, 'caption');

    //or if you file is local
    //$bot->sendPhoto($chat_id, new \CurlFile(<local_file.jpg>), 'caption');

} catch (\TelegramBot\Api\Exception $e) {

    $e->getMessage();

}

如果没有,这是简单的 GET 方法:

https://api.telegram.org/bot<token>/sendPhoto?chat_id=<chat_id>&photo=<file_id>

更多信息Telegram Bot API

【讨论】:

    猜你喜欢
    • 2016-11-11
    • 1970-01-01
    • 2023-03-13
    • 2019-01-19
    • 1970-01-01
    • 2020-09-29
    • 2021-01-18
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多