开发者

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 Fri开发者_开发知识库end\'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.


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.


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.


$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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜