我正在尝试使用php将图像上传到脸书。但我现在收到此错误“未捕获OAuthException:(#324)需要上传文件”。
$app_id = "257711244318488";
$app_secret = "dc4b279079e4eafdfgdfgdfgf6e5b9ef37fb48402";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$fbcheck= $facebook->getUser();
if(is_null($fbcheck) or !$fbcheck or $fbcheck==0)
{
header("Location:{$facebook->getLoginUrl(array('scope' => 'user_status,publish_stream,user_photos'))}");
exit;
}
if($_SERVER['REQUEST_METHOD'] =='POST'){
//$img = realpath($_FILES["pic"]["tmp_name"]);
$facebook->setFileUploadSupport("http://" . $_SERVER['SERVER_NAME']);
$photo = $facebook->api('/me/photos', 'POST',
array(
'source' => $urlParser->fbpostpic($input['ik']),
'message' => 'This photo was uploaded via www.Picslanda.com'
)
);
echo '<p><a target="_blank" href="http://www.facebook.com/photo.php?fbid='.$photo['id'].'">Click here to watch this photo on Facebook.</a></p>';
}
$attachment = array(
'message' => 'Hello friends ',
'name' => "My Name",
'caption' => "My caption",
'link' => "www.site.com",
'description' => 'Description.',
'picture' => "url",
'actions' => array(array(
'name' => 'Get Search',
'link' => 'http://www.google.com'
))
);
$result = $facebook->api(
'/me/feed/',
'post',
$attachment
);
答案 0 :(得分:4)
首先,您需要权限photo_upload
应该是
array('scope' => 'user_status,publish_stream,user_photos','photo_upload')
第二
您需要在php sdk中启用文件上传
$facebook->setFileUploadSupport(true);
如果您要上传照片,则应在文件路径中使用@
// Upload a photo to a user’s profile
// Your app needs photo_upload permission for this to work
$facebook->setFileUploadSupport(true);
$img = '/tmp/mypic.png';
$photo = $facebook->api('/me/photos', 'POST',
array( 'source' => '@' . $img,
'message' => 'Photo uploaded via the PHP SDK!'
));
在https://developers.facebook.com/docs/reference/php/facebook-setFileUploadSupport/
查看更多信息答案 1 :(得分:0)
您需要将photo_upload
添加到您要求的范围内以上传图片。
$facebook->getLoginUrl(array('scope' => 'user_status,publish_stream,user_photos,photo_upload'))
此外,app_secret应该是秘密的,因此在互联网上发布它可能不是一个好主意,因为它允许任何人以您的应用程序名称上传照片。
答案 2 :(得分:0)
问题可能是@
中没有'source'=> '@' . filepath
。当我离开时,我得到你的324 error
。
不幸的是,当我把它放进去的时候,我得到了一个未被捕获的Oauth Exception #1
。