1

我想将一张照片上传到粉丝页面提要,但我不能,我读过一次才能发送它,必须是 POST FORM!这是正确的?

索引.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 数据失败

4

1 回答 1

0

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

我看到 4 件事可能有问题:
1. 您需要确保 $userPhoto 包含指向您的图片的有效服务器路径。
2. 我用“图片”而不是“来源”来发布图片。(但也许两者都有效) 3. 由于您正在上传照片,它应该上传到 //photos 而不是 //feed(或使用 /photos 到相册)
4. 您需要确保您的 $facebook 配置具有 fileUpload设置为 true 或确保编写以下行:
$facebook->setFileUploadSupport(true); 在调用 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>';
 }
}

?>
于 2013-08-27T17:33:58.537 回答