0

我正在尝试制作一个 facebook 应用程序,将照片从计算机上传到 facebook 上的特定相册。我有以下代码,但出现错误:创建表单数据失败。

  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';

知道为什么我会收到错误消息吗?

4

1 回答 1

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);

希望有帮助

于 2012-04-10T10:44:18.287 回答