简体   繁体   中英

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


?>

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM