I use this script here for my Facebook App.
It uploads a photo on a user’s Facebook profile, and creates a new album for that photo.
The script returns “[APP NAME] Photos” as the Album name / title (without quotations).
– [APP NAME] being the name of my Facebook APP –
Basically, I don’t want that Album title. I want to specify an Album title on the script.
What I want is :
- … to be able to specify the Album’s name / title to create, from the script.
- And if possible, specify Album description too.
This is the script –
$root_url = "http://www.WEBSITE.COM/";
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
// Get image from URL
$img = $_GET['i'];
// Change location depending on which type of cover
if($get_set != 1) {
$photo = './PATH/'.$img.''; // Path to the photo on the local filesystem
} else {
$photo = './PATH/'.$img.'';
}
$message = 'THIS IS THE PHOTO CAPTION';
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => '@' . $photo,
'message' => $message,
)
);
// echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
print "<script>window.location = '".$root_url."index.php?cover=uploaded'</script>";
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
echo '<script> window.location = "' . $login_url . '"; </script>';
error_log($e->getType());
error_log($e->getMessage());
}
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} else {
// No user, print a link for the user to login
// To upload a photo to a user's wall, we need photo_upload permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo '<script> window.location = "' . $login_url . '"; </script>';
//echo 'Please <a href="' . $login_url . '">login</a> to continue.';
}
Seeing this one here, I am confident that is possible.
$album_name = 'YOUR_ALBUM_NAME';
$album_description = 'YOUR_ALBUM_DESCRIPTION';
I just don’t know how to work it in there…
Looking forward to solutions. Thanks for your time!
As it says in the documentation of the Photo object:
You are currently using the first option, using the 2nd one requires for you to have an album id, which you first need to create:
The problem is that you’ll have to save this album id for the user to use in the future when the app needs to upload again to the album.