5743

Working with Facebook PHP SDK: Uncaught CurlException: 26: failed creating formpost dat

Question:

I had a look at several stackoverflow posts 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 creating 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 get that error because my code seems to be correct. Do you think there could be a problem with my server / the server's cURL configuration? I dont know much about cURL.

I hope you can help me! I am looking forward for your answers :-)

Greetings, Andreas

Answer1:

Your realpath($path) is not pointing to the actual server image location. If $path is the complete path of the image, then use 'source' => '@' . $path instead.

Answer2:

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; } }

Recommend

  • Is it mandatory to have a HTTPS to communicate with Graph API?
  • Using Office Word to read doc files with PHP
  • How to delete the symlink along with the source directory
  • PHP: black image when cropping using php
  • Mongodb $addToSet of nested object
  • KoGrid JSON Dynamic widgets, with nested server calls
  • Cleave.js Phone CA
  • python cdll can't find module
  • jQuery file download plugin
  • Understanding Intl.DateTimeFormat as a JavaScript object
  • What is the equivalent of Android permissions in iOS development? [duplicate]
  • How to open multiple instances of a program in Linux
  • Not able to display correct data in table -AngularJS
  • include dlls in visual studio c++ 2008
  • conditions for accessors in Coldfusion ORM
  • What is the default HTTP verb in WebApi ? GET or POST?
  • Java Application vs. Java Desktop Application in Netbeans [duplicate]
  • Hash Code in SQL Server?
  • Problems installing Yesod for Haskell
  • Unable to install Git-core+svn by MacPorts
  • Moving Android View and preventing onDraw to be called over and over again
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • Initializer list vs. initialization method
  • Control modification in presentation layer
  • ilmerge with a PFX file
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Fetching methods from BroadcastReceiver to update UI
  • Javascript + PHP Encryption with pidCrypt
  • Hazelcast - OperationTimeoutException
  • Websockets service method fails during R startup
  • RestKit - RKRequestDelegate does not exist
  • Revoking OAuth Access Token Results in 404 Not Found
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Memory offsets in inline assembly
  • Change div Background jquery
  • Turn off referential integrity in Derby? is it possible?
  • How does Linux kernel interrupt the application?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize