-1
這是我在收件人的ID,並試圖發送回一個網址按鈕,但我得到一個「錯誤的請求」的錯誤。的Facebook Messenger平臺發送URL按鈕賦予「錯誤的請求」錯誤
我認爲這個問題是JSON,但我無法弄清楚。
sub post_url_button_to_facebook {
my $reply_recipient = shift;
my %hash = ('recipient'=>{'id'=>$reply_recipient},'message'=>{'attachment'=>{'type'=>'template','payload'=>{'template_type'=>'button','text'=>"This my link",'buttons'=>{'type'=>'web_url','url'=>'https://www.arx.gr/','title'=>"Dev's Website"} }}});
my $post_json_data = JSON::encode_json(\%hash);
my $ua = LWP::UserAgent->new;
my $url = "https://graph.facebook.com/v2.9/me/messages?access_token=" . $permanent_token;
my $req = HTTP::Request->new(POST => $url);
$req->header('Content-type' => 'application/json');
$req->content($post_json_data);
my $resp = $ua->request($req);
if ($resp->is_success) {
my $message = $resp->decoded_content;
send_status_ok();
warn "Received reply: $message\n";
}
else {
warn "HTTP POST error code: ", $resp->code, "\n";
warn "HTTP POST error message: ", $resp->message, "\n";
}
}
是'$ perlmanent_token'定義?它是一個全局變量嗎?這不是你的語言中的詞彙。您可以在發送之前添加一個'print $ req-> as_string'或'$ req-> dump'來查看完整的請求。或者,您可以加載LWP :: ConsoleLogger :: Everywhere來檢查整個事務以查看錯誤。 – simbabque
是的,它的定義。 –
我沒有看到'用戶'節點的'messages'邊緣。你是不是指「收件箱」? – Borodin