Endorkins

The coder’s high

Endorkins header image 2

Facebook Graph API – Upload Photos – “Requires upload file”

December 28th, 2010 · 4 Comments

Quick post here since I see a lot of questions about this out there.

If you’re trying to upload photos via Facebook’s Graph API and you’re getting an OAuthException with a message of “(#324) Requires upload file”, I can help you out.

Something seems to have changed with facebook.php recently – if you’re going to upload files, you have to explicitly set fileUpload to be true in the API. In my setup code, I just add a line as demonstrated below:

// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
'fileUpload' => true,
));

Alternatively, if you’ve already set up your $facebook object, you can call:
$facebook->setFileUploadSupport(true);

Happy coding!

Tags: Uncategorized

4 responses so far ↓

  • 1 admin // Dec 28, 2010 at 5:20 pm

    Thanks to Agence Webmarketing for the initial tip:
    http://stackoverflow.com/questions/3211968/exception-when-uploading-photo-with-facebook-graph-api

  • 2 takien // Jan 2, 2011 at 3:49 pm

    Thank you very much.
    it works fine for me :)

  • 3 Vishal Gupta // Jan 3, 2011 at 1:42 am

    Hi,

    I am actually using pure Rest APIs to upload files from my Java Code.

    From what I can understand, I need to set fileUpload parameter to true. In terms of PHP sdk this is fine but I am not clear on what needs to be done in my case where I am using REST API directly.

    (Changing SDK at this point is not a feasible option for me at this time)

    Any help would be appreciated, Thanks

  • 4 admin // Jan 3, 2011 at 11:03 am

    Hi Vishal,

    It seems that the ‘fileUpload’ parameter is a PHP-only value. That is, it is unique to the SDK and not intrinsic to the SDK. However, the relevant lines from the PHP SDK read as follows:

    if ($this->useFileUploadSupport()) {
    $opts[CURLOPT_POSTFIELDS] = $params;
    } else {
    $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, ‘&’);

    In other words, if the SDK’s file upload support is enabled, set cURL’s ‘POSTFIELDS’ option to be equal to the $params array that was passed in. Otherwise, build a query using the same data and some other values (the else clause). If you need a bit more background, try downloading the PHP SDK here and examining it for more guidance: https://github.com/facebook/php-sdk/ . Best of luck! :)

Leave a Comment