user2479024
user2479024

Reputation: 61

Error "Requires upload file thrown in" from Facebook Graph API

I'm trying to make a script to automatically post a picture to my three fan pages.

Here is the script:

$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'fileUpload' => true,
));
if($_GET["postType"] == "picture"){$type = "picture";}
else {$type = "link";}
// Download the picture, if $type == picture.
if($type == "picture")
{
        $tempFileName = $_SERVER['DOCUMENT_ROOT'].'/TemporaryFiles/';
        $tempFileName .= uniqid().'_'.basename($_GET["pictureUrl"]);
        // Check if content retrieval is successful :D
        if($imgContent = @file_get_contents($_GET["pictureUrl"]))
        {
                @file_put_contents($tempFileName,$imgContent);
        }
}
foreach($pageIDs as $index=>$item)
{
        $fbconfig['pageid'] = $item;
        $facebook->setFileUploadSupport(true);
        if($type == "picture")
        {
                $args = array(
                        'access_token'  => $pageAccessTokens[$index],
                        'message' => $_GET["message"],
                        'source' => '@' . realpath($tempFileName),
                        );
                $post_id = $facebook->api("/" . $albumIDs[$index] . "/photos","post",$args); // Post made :)
        }
        else if($type == "link")
        {
                $args = array(
                        'access_token'  => $pageAccessTokens[$index],
                        'message'       => $_GET["message"],
                        'link' => $_GET["linkUrl"],
                        'picture' => "",
                        );          
                        $post_id = $facebook->api("/$pageid/feed","post",$args); // Post made :)
        }
}
if($type == "picture")
{
        unlink($tempFileName);
}

It's throwing out the following error:

Uncaught OAuthException: (#324) Requires upload file thrown in

I've tried to debug it and have no clue what's wrong with it. If anyone could help, would be grateful.

Upvotes: 2

Views: 4529

Answers (2)

Danieldms
Danieldms

Reputation: 1026

put this in your code after the $ facebook-> api ('/ me');

$this->facebook->setFileUploadSupport(true);

Upvotes: 0

Khawer Zeshan
Khawer Zeshan

Reputation: 9646

You need to add photo_upload to your requested scopes to upload images.

array('scope' => 'user_status,publish_stream,user_photos','photo_upload')

Upvotes: 4

Related Questions