[FIXED] Die bereitgestellte Bilddatei ist ungültig. Bitte überprüfen Sie Ihren Bildpfad erneut. Facebook Graph API-Fehler

Ausgabe

Ich versuche, ein Bild mit dem HTTP-Client von Laravel auf die Facebook-Grafik-API hochzuladen. Aber ich bekomme den oben genannten Fehler.

    $ad_account_id = env("AD_ACCOUNT_ID");
    $access_token = env("ACCESS_TOKEN");
    $image = $request->file('image');

    $response = Http::asForm()
        ->withHeaders(['Content-Type: multipart/form-data'])
        ->post('https://graph.facebook.com/v14.0/act_' . $ad_account_id . '/adimages',
            [
                'filename' => file_get_contents($image),
                'access_token' => $access_token
            ]
        );

    dd(json_decode($response->body()));

In der Dokumentation gibt mir Facebook ein Curl-API-Beispiel wie dieses

curl \
  -F 'filename=@<IMAGE_PATH>' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v<API_VERSION>/act_<AD_ACCOUNT_ID>/adimages

Das Problem dreht sich alles um IMAGE_PATH. Ich habe versucht, einen beliebigen Pfad des hochgeladenen Bildes zu senden, sogar im base64-Format. Ich kann dasselbe Bild mit derselben API in Postman hochladen. Es gibt kein Problem mit access_tokenoder ad_account_id.

Lösung

Mein Problem wurde mit attachder Methode des HTTP-Clients gelöst:

$ad_account_id = env("AD_ACCOUNT_ID");
$access_token = env("ACCESS_TOKEN");
$image = $request->file('image');

$response = Http::attach('filename', file_get_contents($image), 'image.jpg')
    ->post('https://graph.facebook.com/v14.0/act_' . $ad_account_id . '/adimages',
        [
            'access_token' => $access_token
        ]
    );

dd(json_decode($response->body()));


Beantwortet von –
Vüsal Hüseynli


Antwort geprüft von –
Clifford M. (FixError Volunteer)

0 Shares:
Leave a Reply

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

You May Also Like