【问题标题】:Sending photo from URL with Telegram Bot - php使用 Telegram Bot 从 URL 发送照片 - php
【发布时间】:2016-03-10 20:54:29
【问题描述】:

对不起,我的英文写得不好。 当我向电报发送链接时,电报会自动显示该链接。 例如当我发送这个: http://bing.com/az/hprichbg/rb/LaurelMoss_EN-AU9551903343_1366x768.jpg 在电报中你可以看到图片。 此图片链接将过期。 我如何无法将图片链接发送到电报,并让电报抓取它并将其保存在它的服务器上。然后显示没有链接的图像? 而且我无法窃取服务器上的图像。 (我的服务器是周) 我使用这个类来发送一个电报链接:

<?php
include("Telegram.php");

$telegram = new Telegram('my_token');


$content = array('chat_id' => '@my_Channel', 'text' => 'http://bing.com/az/hprichbg/rb/LaurelMoss_EN-AU9551903343_1366x768.jpg');
$telegram->sendMessage($content);
?>

【问题讨论】:

    标签: telegram-bot


    【解决方案1】:

    将照片上传到 bot API 的唯一方法是将图像的内容发送到那里。这就是为什么无论如何您必须将图像下载到您的服务器。但是您可以在 API 请求完成后立即删除它。甚至根本不保存图像:

    $telegram->sendPhoto(['chat_id' => '@my_Channel', 'photo' => file_get_contents('URL')]);

    这是您使用的库中的一个示例https://github.com/Eleirbag89/TelegramBotPHP/

    // Load a local file to upload. If is already on Telegram's Servers just pass the resource id
    $img = curl_file_create('test.png','image/png');
    $content = array('chat_id' => $chat_id, 'photo' => $img );
    $telegram->sendPhoto($content);
    

    `

    【讨论】:

    • 嗨。有人给我另一个答案吗?
    • 这个答案是正确的,你能告诉我们为什么你需要另一个解决方案吗?这是要走的路
    猜你喜欢
    • 2015-09-20
    • 2015-11-24
    • 1970-01-01
    • 2017-06-06
    • 2021-10-03
    • 2021-04-24
    • 2018-11-12
    • 2016-07-09
    • 2021-08-03
    相关资源
    最近更新 更多