Reputation: 1103
What I want to do is create album on facebook and upload photo to the album, now it work to create an album on facebook,but it's not work on uploading photo to album, I dont know why I cannot get the album ID, any solution or idea?
here is my code which is create album and upload photo on facebook
<?//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'name',
'name'=> 'name'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$albums = $facebook->api('/me/albums');
foreach ($albums["data"] as $album) {
//Test if the current album name is the one that has just been created
if($album["name"] == 'name'){
$album_uid = $album["id"];
}
}
//Upload a photo to album of ID...
$photo_details = array(
'message'=> 'test'
);
$file='http://scm-l3.technorati.com/11/12/30/59287/google-logo-682-571408a.jpg'; //Example image file
$photo_details['image'] = '@' . realpath($file);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
//print_r($upload_photo);
?>
thanks
Upvotes: 0
Views: 1790
Reputation: 37018
you can not call realpath
against http file. it's for local files only.
download the file first using curl
, wget
, or one of php internal functions like file_get_contents
/file_put_contents
.
for example:
$file='http://scm-l3.technorati.com/11/12/30/59287/google-logo-682-571408a.jpg'; //Example image file
$output = tempnam(sys_get_temp_dir(), 'blex_');
$cmd = "wget -q \"$file\" -O $output";
exec($cmd);
$photo_details['image'] = '@' . realpath($output);
Upvotes: 0
Reputation: 100175
I dont think you could upload file from url, try:
$pathToFile = "/some/path/someimage.jpg";
$facebook->setFileUploadSupport(true);
............
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//get the album id
$album_uid = $create_album["id"]; // no need for foreach loop
.....
$args = array('message' => 'Some message');
$args['image'] = '@' . realpath($pathToFile); //see realpath use here
$data = $facebook->api('/'. $album_uid . '/photos', 'post', $args);
Hope it helps
Upvotes: 1