我正在尝试制作脚本以自动将照片发布到我的三个粉丝页面。来自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
我试着调试和不知道什么地方错了。如果有人可以帮忙,将不胜感激。
在调试代码时,'@'错误抑制运算符没有帮助。从'file_put_contents'的两个实例中删除它以开始。另外,你是否也会显示_你陷入困境?例如,你是否确保'$ type ==“图片”'?你是否从你的Facebook API调用中获得了'$ post_id'? – halfer