我正在尝试使用PHP发布到FaceBook墙并且收到错误:
Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in /hermes/web09/b924/moo.freecostwebscom2/picslanda/fbpic/library/base_facebook.php on line 1106"
使用以下客户端代码:
$app_id = "257711244318488";
$app_secret = "dc4b279079e4eaff6e5b9ef37fb48402";
$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 :(得分:1)
在使用fb api<br />
$facebook->setFileUploadSupport(true);
答案 1 :(得分:0)
在PHP SDK v.3.x.x中,'req_perms'更改为'scope'。
所以而不是
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access'))}");
尝试
header("Location:{$facebook->getLoginUrl(array('scope' => 'user_status,publish_stream,user_photos,offline_access'))}");