我的应用程序正在向用户发布Facebook Feed。一切正常,但图片不见了。我无法弄清楚原因。
这是$ facebook-> api方法使用的数组:
Array
(
[message] => MyText
[link] => MyLink
[name] => MyName
[picture] => https://lala.herokuapp.com/images/oceanblue.png
[caption] => MyCaption
[description] => MyDescription
)
图片可供访问(不是上面的真实网址),并在浏览器中打开网址时显示。
api返回对象如下所示:
Array
(
[id] => 652685341_10151011701170342
)
非常感谢帮助,谢谢! :)
答案 0 :(得分:4)
我想做同样的事情。您无法将远程图片上传到Facebook,您需要在服务器上显示图片,以便我在我的服务器上下载图像然后上传它。 这是我的代码:
/**
* Post photo on facebook
* This function requires the user to be logged in
* This function requires the 'publish_stream' permission
*
* Fetches the picture from remote URL and uploads it to facebook
* @param string $picture Picture URL
* @param string $description Description to place in caption
* @param string $link Link to place in caption
* @param string $albumId Id of the previously created album
*/
function postPhotoOnFacebook($picture, $description, $link, $albumId){
global $userId, $facebook;
$tempFilename = $_SERVER['DOCUMENT_ROOT'].'/temp/';
$tempFilename .= uniqid().'_'.basename($picture);
if ($userId) {
try {
if($imgContent = @file_get_contents($picture)){
if(@file_put_contents($tempFilename, $imgContent)){
$photo_details = array('message' => "$link $description");
$photo_details['image'] = '@' . realpath($tempFilename);
$data = $facebook->api('/'.$albumId.'/photos', 'post', $photo_details);
unlink($tempFilename);
}
}
} catch (FacebookApiException $e) {
error_log($e);
$userId = null;
}
}
}
这个堆栈问题有很多帮助:Upload a remote photo to an upload
希望有所帮助!