php - 来自 Facebook Graph API 的错误 "Requires upload file thrown in"

标签 php facebook-graph-api

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

这是脚本:

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

它抛出以下错误:

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

我尝试过调试它,但不知道它出了什么问题。如果有人能提供帮助,将不胜感激。

最佳答案

您需要将 photo_upload 添加到您请求的范围才能上传图片。

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

关于php - 来自 Facebook Graph API 的错误 "Requires upload file thrown in",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17222378/

相关文章:

php - 谁能帮我弄清楚这段代码有什么问题?

php - 读取 csv 文件的最快方法

facebook-graph-api - Graph API 将变音字母字符作为问号返回

PHP 和 Facebook : facebook-debug a URL using CURL and Facebook debugger

facebook - tfbnw.net 电子邮件地址是否可以用于 facebook 登录

PHP/jQuery AJAX JSON 错误

php - mb_strlen() 够了吗?

php - 将嵌套文件夹(子子文件夹)重定向到自己的index.php

facebook - 站点 URL 已被识别为恶意和/或滥用

javascript - 使用 js sdk 无法找到 facebook 帖子 id