Upload image from facebook app

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;
}


?>

Answers


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/


Need Your Help

Will Apple Pay work with Mobile Safari and If not why?

mobile-safari applepay

I was asked to see whether apple pay will work with mobile safari and if possible to integrate into our current mobile website/website. When i did my research I found that it only works with a nati...

Django AWS RDS MySQL Error: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')

python mysql django ssl amazon-rds

I'm having some trouble connecting to my AWS RDS Database from my Python/Django application. I'm getting this error when trying to run my application locally: