如何將以下 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_init并curl_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 }}
uj5u.com熱心網友回復:
要添加訪問令牌,您只需添加另一個標頭:
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer ' . $accessToken;
當我在 word 中呼叫端點拼寫錯誤時,也會出現如下languauge錯誤。應該language
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/497458.html
