我正在尝试在电报频道上发送自动调查(有点选择题)。但是,sendPoll
函数不起作用。
链接:https://t.me/testwalachannel
我尝试通过API发送测试消息,并且可以正常工作。
代码段:
<?php
$apiToken = "##### MY API KEY #####";
$data = [ 'chat_id' => '@testwalachannel', 'message' => 'This is test message' ];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" . http_build_query($data) );
?>
参考:https://core.telegram.org/bots/api#sendmessage
类似地,我尝试发送联系人,并且成功了。但是,当我使用sendPoll
方法发送民意调查时,它显示了一个错误。
参考:https://core.telegram.org/bots/api#sendpoll
示例代码:
<?php
$apiToken = $apiToken = "##### MY API KEY #####";
$options = array("Devendra","noneofthese","Sourabh") ;
$data = [ 'chat_id' => '@testwalachannel', 'question' => 'This is whose number 12345 ?', 'options' => $options ];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendPoll?" . http_build_query($data) );
?>
<?php
$apiToken = $apiToken = "##### MY API KEY #####";
$options = array("Devendra","noneofthese","Sourabh") ;
$data = [ 'chat_id' => '@testwalachannel', 'question' => 'This is whose number 12345 ?', 'options' => $options ];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendPoll?" . http_build_query($data) );
?>
错误响应:
{"ok":false,"error_code":400,"description":"Bad Request: can't parse options JSON object"}
答案 0 :(得分:0)
我解决了这个问题。
我只需要替换'options'
=> json_encode($options)