0
インラインボットを作りたかった!そして私はこれを行うとき:インラインクエリ結果エラーを送信する(電報)
function sendResponse($url, $data){
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('inline_query_id' => $data['inline_query_id'], 'results' => json_encode($data['results'])));
$output = curl_exec($ch);
return $output;
}
この文句を言わない仕事、(ヘッダの有無にかかわらず)エラー:{"ok":false,"error_code":400,"description":"[Error]: Bad request: Field \"message_text\" must be of type String"}
をしかし、私はこのようにそれを行うとき:
function sendResponse($url, $data){
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_URL, $url.'?inline_query_id='.rawurlencode($data['inline_query_id']).'&results='.rawurlencode(json_encode($data['results'])));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $q);
$output = curl_exec($ch);
return $output;
}
それは働きます!問題は2番目のメソッドURIが大きすぎて使用できないということです!
これらのデータを送信する方法は問われません。ありがとう!
と$データを作成するためのコードはここにある:
$result = connectWebsite(SITE_SEARCH_URL, urlencode($update['inline_query']['query']));
$result = json_decode($result);
$output = array();
$output['inline_query_id'] = $update['inline_query']['id'];
$i = 0;
foreach($result as $post){
$data = array();
$data['type'] = 'article';
$data['id'] = strval($post->ID);
$data['title'] = '('.$post->atypes.') '.$post->title;
if(strlen($post->content) > 2100)
$tmp = substr($post->content, 0, 2096).'...';
$data['message_text'] = '<b>'.$post->title.'</b>'.ucwords($post->genre, ',').$tmp;
$data['parse_mode'] = 'HTML';
if(strlen($post->content) > 200)
$tmp = substr($post->content, 0, 196).'...';
//$data['description'] = ucwords($post->genre, ',').' | '.$tmp;
$output['results'][$i] = $data;
$i++;
if($i == MAX_RESULTS)
break;
}
sendResponse(API_URL.'answerInlineQuery', $output);
オハイオ州のためのURLの長さの問題もなく
おかげで誰もが私のインラインクエリ結果(または他のコマンド)を送信することができます。重複しているなどの理由で-1を与えている場合は、それも回答してください(または少なくともリンク)。 -1の教授! ありがとう –
api呼び出しから取得するメッセージからデバッグするだけで、 '[Error]:Bad request:Field \" message_text \ "はString型でなければならないので、' message_text'がStringであることを確認してください。 – itzmukeshy7
@ itzmukeshy7です! –