从脸谱app上传图片

时间:2012-03-29 06:54:02

标签: php facebook

我正在尝试从Facebook应用上传图片。我收到以下错误:致命错误:未捕获的CurlException:26:在第886行的/storage/content/00/103300/gjutveckling.se/public_html/fb/src/base_facebook.php中创建的formpost数据失败

这是我的代码。奇怪的是,我让它工作,但如果突然它停止工作,那么所有。这可能是一个与SSL相关的问题,我刚刚换了一个新问题吗?任何建议必须赞赏!

<?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);



?>

我试过这个,它没有给我一个错误,但没有上传照片。

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


?>

1 个答案:

答案 0 :(得分:0)

请试试这个

$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);

看到这个链接 http://pramodsivadas.co.in/2011/11/upload-an-image-to-a-facebook-album-facebook-php-sdk/