Sourav
Sourav

Reputation: 17530

Upload photos to Facebook Album from an app

I've used

'req_perms' => 'publish_stream,status_update'

The error I'm getting is

Fatal error: Uncaught CurlException: 26: failed creating formpost data thrown in facebook.php on line 589

My upload code:

$facebook->setFileUploadSupport(true);
$args = array('message' => 'My Friend\'s');
$args['image'] = '@' . realpath('http://mysite/img/img.jpg');
$data = $facebook->api('/me/photos', 'post', $args);
print_r($data);

I just want to upload the photo to an existing album or already created album. What would working code be?

Another code

$photo_details = array('message'=>$_REQUEST['arttitle'],'source'=> '@' . realpath( $_FILES[file]tmp_name]));
$facebook->api('/me/photos','POST',$photo_details);

results in

Fatal error: Uncaught OAuthException: (#324) Requires upload file thrown in facebook.php on line 522

I tried other answers from Stack Overflow, but none of them worked in my case.

Upvotes: 1

Views: 14057

Answers (3)

Sourav
Sourav

Reputation: 17530

I tried the code below, and it worked perfectly.

$facebook->setFileUploadSupport(true);

$album_details = array(
    'message'=> 'album description goes here',
    'name'=> 'album name goes here'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);

// Upload a picture
$photo_details = array(
    'message'=> 'photo description'
);
$photo_details['image'] = '@' . realpath('/the/path/to/your/image.jpg');
$upload_photo = $facebook->api('/'.$create_album['id'].'/photos', 'post', $photo_details);

echo $upload_photo['id']; // The id of your newly uploaded pic.

Upvotes: 5

ifaour
ifaour

Reputation: 38135

You can't use realpath() with URLs. If the image is located on the same server, try to provide that path instead. Please refer to this answer for more info.

Upvotes: 1

user737767
user737767

Reputation: 1024

$args = array(  
    'message' => 'My Friend\'s',  
    "access_token" => "urtoken",  
    "image" => '@' . realpath('http://mysite/img/img.jpg'); 
);  


$data = $facebook->api('/me/photos', 'post', $args);

try this code

Upvotes: 0

Related Questions