我正在尝试创建一个Facebook应用程序,将照片从计算机上传到Facebook上的特定相册。我有下面的代码,但我收到一个错误:创建formpost数据失败。
require_once 'include.php';
$config = array(
'appId' => $app_id,
'secret' => $app_secret,
);
$facebook = new Facebook($config);
$user = $facebook->getUser();
if($user && isset($_POST['submit'])){
try {
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'Album desc',
'name'=> 'Album name'
);
$create_album = $facebook->api('/me/albums', 'POST', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$photo = realpath($_FILES['miss_photo']['tmp_name']);
$photo2 = $photo . '.jpg';
//echo $photo2; exit();
$photo_details['image'] = '@' . $photo2;
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'POST', $photo_details);
} catch (FacebookApiException $e) {
echo ($e->getMessage());
}
}
else
echo 'error';
我知道为什么会收到错误消息?
答案 0 :(得分:0)
您无法以这种方式使用文件,您需要提供文件的路径,例如:
photo_details = array(
'message'=> 'some test'
);
$photo_details['image'] = '@' . realpath('/path/to/your/image_file.jpg');
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
希望有所帮助