Facebook错误:“创建formpost数据失败”将照片上传到粉丝页面

时间:2013-06-28 19:50:23

标签: php facebook

我想上传一张照片到粉丝页面Feed,但我不能,我读过一次发送它,必须是POST表格!它的权利?

的index.php

<html>
<head>
    <title>Index Page Facebook</title>
</head>
<body>
    <?php 
        require('config.php');


        if($user){
            $_SESSION['user_id'] = $user;
?>
        <form action="facebook3.php" method="post" accept-charset="utf-8">
            Message <input type="text" name="message"> <br>
            Photo: <input type="file" name="pictureFile">
                <input type="submit" value="Postar">
        </form>
<?php       
            exit();         
        }else{
    ?>
            <a href="<?php $facebook->getLoginUrl(array('scope' => $fbPermissions, 'redirect_uri' => $homeurl)); ?>">Login Facebook</a>;
    <?php       
        }
    ?>  
</body>
</html>  

fb.php

<?php
include_once("config.php");
//destroy facebook session if user clicks reset


if($_POST)
{
    //$loginUrl = $facebook->getLoginUrl(array('scope' =>  'manage_pages'));    
    //$loginUrl = $facebook->getLoginUrl(array('scope' =>  'publish_stream'));  
    @include_once("config.php");


    //Post variables we received from user
    $userPhoto  = $_FILES["pictureFile"]["tmp_name"];
    $userMessage    = $_POST["message"];

    if(strlen($userMessage)<1)
    {
        //message is empty
        $userMessage = '';
    }

        //HTTP POST request to PAGE_ID/photos with the publish_stream
        $post_url = '/228433913910358/feed';
        //posts message on page statues

        $msg_body = array(
        'source'=>'@'.$userPhoto,
        'message' => $userMessage
        );

    if ($user) {
      try {
            $postResult = $facebook->api($post_url, 'post', $msg_body );
        } catch (FacebookApiException $e) {
        echo $e->getMessage();
      }
    }else{
     header("Location: index.php ");
    }

    //Show sucess message
    if($user && !empty($postResult))
     {
         echo '<html><head><title>Message Posted</title><link href="style.css" rel="stylesheet" type="text/css" /></head><body>';
         echo '<div id="fbpageform" class="pageform" align="center">';
         echo '<h1>Your message is posted on your facebook wall.</h1>';
         echo '<a class="button" href="'.$homeurl.'">Back to Main Page</a> <a target="_blank" class="button" href="http://www.facebook.com/'.$fbuser.'">Visit Your Page</a>';
         echo '</div>';
         echo '</body></html>';
     }
}

?>

所以,我试过邮寄,直接写路径$ photo,但错误仍然存​​在!

创建formpost数据失败

2 个答案:

答案 0 :(得分:0)

我知道这是一个迟到的回复,但对于其他可能会落在这里的人......

我看到4件可能有问题的事情:
1.您需要确保$ userPhoto包含有效的服务器路径到您的图片 我使用“图像”而不是“源”来发布图像。 (但也许两者都有效) 3.由于您要上传照片,因此应该上传到//照片而不是// Feed(或使用/照片的相册) 4.您需要确保您的$ facebook配置将fileUpload设置为true或确保写入行:
$ facebook-&GT; setFileUploadSupport(真);在致电api之前。

所以代码看起来像是这样(未经测试的代码)

<?php
include_once("config.php");
//destroy facebook session if user clicks reset

if($_POST)
{
    //$loginUrl = $facebook->getLoginUrl(array('scope' =>  'manage_pages'));    
    //$loginUrl = $facebook->getLoginUrl(array('scope' =>  'publish_stream'));  
    @include_once("config.php");

    $facebook->setFileUploadSupport(true);


//Post variables we received from user
$userPhoto  = $_FILES["pictureFile"]["tmp_name"];
$userMessage    = $_POST["message"];

if(strlen($userMessage)<1)
{
    //message is empty
    $userMessage = '';
}

    //HTTP POST request to PAGE_ID/photos with the publish_stream
    $post_url = '/228433913910358/photos';
    //posts message on page statues

    $msg_body = array(
    'image'=>'@'.$userPhoto,
    'message' => $userMessage
    );

if ($user) {
  try {
        $postResult = $facebook->api($post_url, 'post', $msg_body );
    } catch (FacebookApiException $e) {
    echo $e->getMessage();
  }
}else{
 header("Location: index.php ");
}

//Show sucess message
if($user && !empty($postResult))
 {
     echo '<html><head><title>Message Posted</title><link href="style.css" rel="stylesheet" type="text/css" /></head><body>';
     echo '<div id="fbpageform" class="pageform" align="center">';
     echo '<h1>Your message is posted on your facebook wall.</h1>';
     echo '<a class="button" href="'.$homeurl.'">Back to Main Page</a> <a target="_blank" class="button" href="http://www.facebook.com/'.$fbuser.'">Visit Your Page</a>';
     echo '</div>';
     echo '</body></html>';
 }
}

?>

答案 1 :(得分:0)

here,这个页面解释了很多关于Facebook上的帖子图片