After some hardwork I have some code that uploads an image to Facebook, but now the problem is that it always creates a new album.
I want to modify the code so that it o
First you want to check to see if the album you are creating exists, otherwise Facebook will keep generating the same album with the same name.
$album = $facebook->api($param);
if (!$album) {
$album_details = array(
'message'=> 'Your album description goes here',
'name'=> $albumName
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
$album_uid = $create_album['id'];
} else {
$album_uid = $album[0]['object_id'];
}
Once you've got the album id, you can upload your photo like so:
$photo_details = array(
'message'=> 'Photo Description Goes Here',
'image'=> '@' . realpath($theUploadFile)
);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
I wrote a good tutorial that has this feature in it among many others. My photo upload features is built in with a multi-select and allows you to upload photos and videos at the same time. You can view the entire tutorial and download the package here: http://www.epixseo.com/index.php/facebook-php-3-3-1-and-javascript-sdk-graph-api-tutorial/
UPDATE
The $param variable contains the method, which in this case is a fql query, and the actual fql query... In this instance, an album query could be like so:
$param = array(
'method' => 'fql.query',
'query' => 'SELECT object_id FROM album WHERE owner="'.$user.'" AND name="'.$albumName. '"'
);