2

我正在尝试制作一个脚本来自动将图片发布到我的三个粉丝页面。

这是脚本:

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

它抛出以下错误:

未捕获的 OAuthException: (#324) 需要上传文件

我试图调试它,但不知道它有什么问题。如果有人可以提供帮助,将不胜感激。

4

2 回答 2

4

您需要将 photo_upload 添加到您请求的范围以上传图像。

array('scope' => 'user_status,publish_stream,user_photos','photo_upload')
于 2013-06-20T20:55:18.027 回答
0

把它放在你的代码中 $ facebook-> api ('/me');

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

于 2013-11-12T02:59:41.960 回答