Hullo Geek,我正在尝试集成nexmo facebook-messager使用PHP将api传递到我的应用程序中,但是,在提交数据之后,我得到了这个错误。
bodyType=com.nexmo.chatapp.sandbox.messages.Message"}不支持
{“标题”:“内容类型'application/x-www-form-urlencoded‘
这是代码
$message = array(
"from" => array("type" => "messenger", "id" => "107XXXXXXXX"),
"to" => array("type" => "messenger", "id" => $FB_RECIPIENT_ID),
"message" => array("content" => array(
"type" => "text",
"text" => "This is a Facebook Messenger Message sent from the Messages API. Ashan, please enjoy"
)
)
);
$message = json_encode($message);
//echo $message; die();
$ch = curl_init();
$url = "https://messages-sandbox.nexmo.com/v0.1/messages";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERNAME, "7af532c1:lWk9QFKaaGFgLz6u");
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/json");
curl_setopt($ch, CURLOPT_HEADER, "Accept: application/json");
curl_setopt($ch, CURLOPT_NOBODY, FALSE); // remove body
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
$head = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);我的目标是通过nexmo向信使发送消息。
发布于 2020-05-22 08:26:15
错误出现在与内容一起发送的标头上。虽然是错误,
bodyType=com.nexmo.chatapp.sandbox.messages.Message"} {“
”:“类型‘application/x form-urlencoded’不支持HEADERS (未定义的)。因此,应用了默认的'application/x-www-form-urlencoded内容类型
通过添加这一行代码解决了这个问题。
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Accept: application/json"));
//curl_setopt($ch, CURLOPT_HTTPHEADER, "Accept: application/json");对于NEXMO,使用JSON类型的数据。现在在空中
https://stackoverflow.com/questions/61932027
复制相似问题