Working with Facebook PHP SDK: Uncaught CurlException: 26: Failed to create formpost dat

I looked at several stackoverflow messages about this error message, but none of them worked for me.

I want to upload a photo to facebook:

public function uploadPhoto($path){
    $photoSettings = array(
        'access_token'=> $this->facebook->getAccessToken(),
        'name' => 'uploaded foto',
        'source' => '@' . realpath($path)
    );

    $photo = $this->facebook->api('me/photos','POST',$photoSettings);
}

When I call this function, I get the following error message:

Uncaught CurlException: 26: failed to create formpost data

I am 100% sure that the image I want to upload exists (and the path is correct).

This is my facebook initialization: (fileUpload is true)

$this->facebook = new Facebook(array(
          'appId'  => $this->config['appId'],
          'secret' => $this->config['appSecret'],
          'fileUpload' => true,
          'cookie' => true
    ));

I really don't understand why I am getting this error because my code seems to be correct. Do you think there may be a problem with the cURL server / server configuration? I do not know much about cURL.

I hope you help me! I look forward to your answers :-)

Hello Andreas

0
2

realpath($path) . $path - , 'source' => '@' . $path.

+1
I kept getting "CurlException: 26: failed creating formpost data" 

Here is my working code for uploading a photo from the same directory as the PHP page communicating with   Facebook:
$facebook    =  new Facebook(array(
'appId'      =>'*****',
'secret'     =>'*******',
'fileUpload' => true,
'cookie'     => true
));
 $user  =   $facebook ->getUser();
 if($user) 
 {  
$facebook->setFileUploadSupport(true);
$args = array(
    'message' => 'TEst from App.',
    'image' => '@' . realpath('awesome.jpeg')
);
try {
    $data = $facebook->api('/me/photos', 'post', $args);
} catch(FacebookApiException $e) {
    echo "ERROR: " . $e;
}

 }
+1

Source: https://habr.com/ru/post/1531583/


All Articles