My app is posting to the users Facebook feed. Everything works fine, but the picture is missing. I cannot figure out why.
This is the array used by the $facebook->api method:
Array
(
[message] => MyText
[link] => MyLink
[name] => MyName
[picture] => https://lala.herokuapp.com/images/oceanblue.png
[caption] => MyCaption
[description] => MyDescription
)
The image is accessible (not the real url above) and shows up when I open the url within a browser.
The api return object looks like this:
Array
(
[id] => 652685341_10151011701170342
)
Help is much appreciated, thanks! :)
I wanted to do the same thing. You can't upload a remote picture to facebook, you need to have the picture on your server so I download the image on my server and then upload it. Here's my code :
/**
* 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;
}
}
}
This stack question helped a lot : Upload a remote photo to an upload
Hope that helps!