我想做同样的事情。您无法将远程图片上传到 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;
}
}
}
这个堆栈问题很有帮助:将远程照片上传到上传
希望有帮助!