【发布时间】:2016-01-25 06:57:08
【问题描述】:
我正在尝试在 Telegram 中迈出第一步,我也是 PHP 的新手......
我已经在我的 Windows 7 电脑上配置了带有 PHP 5.6.14 和 SSL 的 Apache 2.4,它在 http 和 https 中运行良好。
然后我尝试遵循此 Telegram Bot 教程https://www.youtube.com/watch?v=hJBYojK7DO4。一切正常,直到我必须创建一个像这样的简单 PHP 程序
<?php
$botToken = "<my_bot_token>";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents($website."/getUpates");
print_r($update);
?>
当我尝试放入浏览器时
https://localhost/Telegram/MyYouTubeTutorialBot/YouTubeTutorialBot.php
回应是
Warning: file_get_contents(https://api.telegram.org/<my_bot_token>/getupates): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in <my_php_file_location> on line 6
我在网上搜索过类似的问题,但没有解决任何问题:最有趣的回答是这个问题file_get_contents - failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found,但我不明白如何适应我的情况。
在其他回复中有使用 curl 的建议,但我想解决持续的 file_get_contents 功能。
我认为这不是 PHP 问题,而是我的配置中某处的问题......但我不知道在哪里
有什么建议吗?
非常感谢您
切萨雷
添加注释
正如@aeryaguzov 在 cmets 中建议的那样,我的原始代码中存在拼写错误......
这是现在可以使用的固定代码...
<?php
$botToken = "<my_bot_token>";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents($website."/getUpdates");
print_r($update);
?>
【问题讨论】:
-
我在您的警告中看到了
。你发送的是真正的令牌而不是这个占位符吗? -
是的!有一个真正的令牌.......
-
也许你只是使用了错误的网址...试试 $website = "api.telegram.org/bot/".$botToken.''; ,还有什么 var_dump(base64_encode($website)); 给你?
-
我试过了,但没有任何改变.... var_dump(base64_encode($website)); 的结果以下是......字符串(100)“aHR0cHM6Ly9hcGkudGVsZWdyYW0ub3JnL2JvdDE3MDE4NDEwMzpBQUVKbUVzbXo1MVVFbTM5aDc2T3NxcUlrVEZGX1MzNUQ4dw=="
-
@Cesare 你的拼写再次无效:使用“getUpdates”而不是“getUpates”
标签: php telegram apache2.4 php-5.6 telegram-bot