Ad

Facebook Uploading Image With Laravel Framework

I am trying to uploading image to the facebook page using GraphQL API

Bellow is some code I am using

use SammyK\LaravelFacebookSdk\LaravelFacebookSdk as Facebook;
try {
     $token = $token ? $token : $this->access_token;
     // $fb = app(Facebook::class);
     $fb = new Facebook(array( 'appId' => '366774494090568', 'secret' => '9f847b900176325ce45d87dec94e81ea', 'fileUpload' => true));
     //$fb->setFileUploadSupport(true);
      //$fb->setDefaultAccessToken($token);
            return $fb;
    } catch (\Exception $e) {
            throw $e;
    }
$payload = unserialize($scheduledPost->payload);
            $images = $payload['images'];
            $timezone = $payload['scheduled']['publishTimezone'];
            $appUrl = config("app.url");
            $mediaIds = [];
            $mediaCount = 0;
            foreach($images as $image){
                $relativePath = $image['relativePath'];
                $fullPath = $appUrl."/".$relativePath;
                $media = ["url" => $fullPath, "published" => false];
                $uploadResponse = $this->uploadMedia($media);
                $mediaId = $uploadResponse['id'];
                $mediaIds["attached_media[$mediaCount]"] = "{'media_fbid': '$mediaId'}";
                $mediaCount++;
            }
public function uploadMedia($media)
    {
        $fb = $this->setAsCurrentUser($this->access_token);
        $response = $fb->post("/{$this->original_id}/photos", $media);
        return $response->getDecodedBody();
    }

When I use setFileUploadSupport(true), there is error that function is not defined

If I use new Facebook with 'fileupload' => 'true' it gives me error like bellow

exception: "Symfony\Component\Debug\Exception\FatalThrowableError"
file: "C:\Users\king\Documents\work\01_Unicilix\API\vendor\sammyk\laravel-facebook-sdk\src\LaravelFacebookSdk\LaravelFacebookSdk.php"
line: 28
message: "Argument 1 passed to SammyK\LaravelFacebookSdk\LaravelFacebookSdk::__construct() must implement interface Illuminate\Contracts\Config\Repository, array given, called in C:\Users\king\Documents\work\01_Unicilix\API\app\Traits\Facebook\FacebookTrait.php on line 22
Ad

Answer

This code was very correct.

The problem was I can get storage image from url because of the server(ubunt) permmission.

Ad
source: stackoverflow.com
Ad