Convert Faceboook Meta cUrl to PHP



如何将以下cUrl转换为PHP

curl -i -X POST 
https://graph.facebook.com/v12.0/FROM_PHONE_NUMBER_ID/messages 
-H 'Authorization: Bearer ACCESS_TOKEN' 
-H 'Content-Type: application/json' 
-d '{ "messaging_product": "whatsapp", "to": "TO_PHONE_NUMBER", "type": "template", "template": { "name": "hello_world", "language": { "code": "en_US" } } }'

我想使用标准的curl_initcurl_exec来执行url函数。

到目前为止,我已经尝试了以下方法。

$endpoint = "https://graph.facebook.com/v12.0/".$whatsappPhoneNumberId."/messages";

$headers = array();
$headers[] = 'Content-Type: application/json';
$bodyFields = [
"messaging_product" => "whatsapp",
"to" => "XXXXXXXXXXX",
"type" => "template",
"template" => [
"name" => "hello_world",
"languauge" => [
"code" => 'en_US',
]
],
];
$cUrl = curl_init($endpoint);
curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cUrl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cUrl, CURLOPT_POSTFIELDS, json_encode($bodyFields));

$response = curl_exec($cUrl);
curl_close($cUrl);

我需要添加访问令牌,并且在调用端点

时也得到如下错误
{"error":{"message":"(#100) Unexpected key "languauge" on param "template".","type":"OAuthException","code":100 }}

要添加访问令牌,只需添加另一个头:

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer ' . $accessToken;

也得到如下错误,当我调用端点-字languauge拼写错误。应该是language

相关内容

  • 没有找到相关文章

最新更新