0

I'm trying to upload image from a Facebook app. I get the following error: Fatal error: Uncaught CurlException: 26: failed creating formpost data thrown in /storage/content/00/103300/gjutveckling.se/public_html/fb/src/base_facebook.php on line 886

This is my code. The strange thing is that i got it to work, but then all if the sudden it stopped working. Can this be a SSL related problem, I just got a new one? Any suggestions must appreciated!

<?php   



$facebook = new Facebook(array(
                       'appId'  => $appid,
                       'secret' => $appsecret,
                      'fileUpload' => true, 
                       'cookie' => true,));

$facebook->setFileUploadSupport(true);  

$FILE_PATH = 'imdage_' . $user_id . '.jpg';

$args = array('message' => 'message');

$args['image'] = '@' . realpath($FILE_PATH);

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



?>

I tried this aswell, it doesn't give me an error, but no photo is uploaded.

 <?php


function upload_to_facebook($image_data, $access_token)
    {
 $facebook = new Facebook(array(
'appId'  => 'xxx',
'secret' => 'xxx',
));

$facebook->setFileUploadSupport(true);
$albums = $facebook->api('/me/albums', 'get', array('access_token' => $access_token));
foreach ($albums[data] as $album)
{
if ($album['name'] == $image_data['album_name'])
{
$album_id = $album['id'];
}
}

if (!$album_id)
{ 
//Create an album
$album_details = array(
'message'    => 'Album by FB APP',
'access_token'   => $access_token,
'name'   => $image_data['album_name']
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you’ve just created
$album_id = $create_album['id'];
}

//Upload a photo to album of ID…
$photo_details = array(
'message'    => 'test image',
'access_token'   => $access_token,
);

$photo_details['skrivreglerny.png'] = '@' . realpath($image_data['file']);

$upload_photo = $facebook->api('/'.$album_id.'/photos', 'post', $photo_details);

return $upload_photo;
}


?>
user1009453
  • 707
  • 2
  • 11
  • 28

1 Answers1

0

Try this please

$photo_details = array(
        'message'        => 'message',
        'access_token'   => 'USER ACCESS TOKEN',
    );

    $photo_details['image'] = '@'.realpath($image_data['file']);
    $upload_photo = $facebook->api(('/me/photos', 'post', $photo_details);

see this link http://pramodsivadas.co.in/2011/11/upload-an-image-to-a-facebook-album-facebook-php-sdk/

Pramod Sivadas
  • 873
  • 2
  • 9
  • 28
  • Thank you for your answer, sorry for slow response. I tried the code on your site. Unfortunately I get the following error: Parse error: syntax error, unexpected T_STRING, expecting ')' in /storage/content/00/103300/gjutveckling.se/public_html/fb/dela/index.php on line 110 Have you tried the code yourself? – user1009453 Mar 29 '12 at 11:49
  • I think the issue may be with single quotes. While copying from the website single quotes are replaced with some other characters. Tty replacing all single quotes with the correct one. – Pramod Sivadas Mar 29 '12 at 11:59
  • Thank's for staying with me on this. The error disappeared when I repleced all the strange charachters with single quotes, but no image is uploaded. I will post my code below so you can see it. Edit: I wasn't aloud to answer my own question, so I will paste it in my orgiginal question. – user1009453 Mar 29 '12 at 12:39