[FIXED] WhatsApp-Geschäft – POST Media

Ausgabe

Ich versuche, einen POST mit der Facebook Graph API zu erstellen. Ich habe mich an die Dokumentation gehalten . Ich trenne auch die Post-Felder als: Datei, Typ und Nachrichtenprodukt: gleiches Ergebnis.

$this->endpoint = 'PHONE_NUMBER_ID/media';
$this->config->default_access_token = 'XXXXXXXX';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v14.0/'.$this->endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
    'file' => '@/var/www/html/6218062.pdf;type=application/pdf',
    'messaging_product' => 'whatsapp'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

$headers = array();
$headers[] = 'Authorization: Bearer '.$this->config->default_access_token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

print_r($result);

Das ist das Ergebnis:

{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1,"fbtrace_id":"A_A8o81x3K5kCpGD5cP1rw6"}}

Ich kann Nachrichten und alles senden, aber ich kann keine Nachrichten mit Dokumenten vom lokalen Server senden, nur von einem externen Server, zum Beispiel: https://sitename.com/file/doc.pdf .

Ich möchte Dateien von meinem lokalen Server verwenden und als Nachricht senden.

Kann mir jemand helfen?

Lösung

Ich habe das Problem gelöst.

Hier ist der Arbeitscode.

$this->endpoint = 'PHONE_NUMBER_ID/media';
$this->config->default_access_token = 'XXXXXXXX';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v14.0/'.$this->endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
    'file' => curl_file_create('/var/www/html/6218062.pdf', 'application/pdf'),
    'messaging_product' => 'whatsapp'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$headers = array();
$headers[] = 'Authorization: Bearer '.$this->config->default_access_token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

print_r($result);


Beantwortet von –
Ezequiel Villarreal


Antwort geprüft von –
David Marino (FixError Volunteer)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like