我的问题已经在这里讨论了 couldn't open file "" error in Facebook PHP API
我的php脚本是
//variables we are going to post to facebook
$fbPermissions = 'publish_stream,user_photos'; //Required facebook permissions
$PicLocation = 'fb_cover_images/cover7.jpg';
$msg_body = array(
'message' => 'I liked this pic from '. $homeurl .
' it is perfect for my cover photo.',
'url' => "http://my_site.com/$PicLocation"
);
if ($fbuser){ //user is logged in to facebook, post our image
try {
$uploadPhoto = $facebook->api('/me/photos', 'post', $msg_body );
}
catch (FacebookApiException $e) {
echo $e->getMessage(); //output any error
}
}
else{
$loginUrl = $facebook->getLoginUrl(
array('scope'=>$fbPermissions,'return_url'=>$return_url));
header('Location: ' . $loginUrl);
}
如果我设置'url' => "http://my_site.com/$PicLocation"
然后获取
(#200)权限错误
如果我设置'url' => "@http://my_site.com/$PicLocation"
然后获取
消息但是如果我点击"http://my_site.com/fb_cover_images/cover7.jpg"
,我可以查看图像,并且对文件夹+图像的权限设置为777。
请指导我做错了什么...... 我已经搜索但失败了。
我也试过[PHP + Facebook:如何在墙上上传照片?但同样的垃圾邮件(#200) Permissions error
另外Upload Photo To Album with Facebook's Graph API 我不知道FB API到底发生了什么。
答案 0 :(得分:0)
在设置Facebook后,尝试将以下行添加到代码顶部:
$facebook->setFileUploadSupport( true );
然后,将您的$msg_body
更改为以下内容:
$msg_body = array(
'name' => 'I liked this pic from '. $homeurl . ' it is perfect for my cover photo.',
'source' => "http://my_site.com/$PicLocation"
);
name
是图片的标题,source
是文件的网址。如果要引用本地文件,则只需要将@
作为前缀。