0

嗨,伙计们,我是 php programin 和 facebook 应用程序的新手,我找到了这段代码,它适用于 TEXT 帖子,但我的要求是我也必须上传图片,我尝试通过 addin ['source' => '$image_source'] 在 arrey 但不起作用...我如何上传照片?

<?php
include_once("config.php");


if($_POST)
{
    //Post variables we received from user
    $userPageId     = $_POST["userpages"];
    $userMessage    = $_POST["message"];
    $image_source = "http://www.example.com/image.jpg"
    if(strlen($userMessage)<1) 
    {
        //message is empty
        $userMessage = 'No message was entered!';
    }

        //HTTP POST request to PAGE_ID/feed with the publish_stream
        $post_url = '/'.$userPageId.'/feed';

        //posts message on page statues 
        $msg_body = array(
        'message' => $userMessage,
        'source' => '$image_source'
        );

    if ($fbuser) {
      try {
            $postResult = $facebook->api($post_url, 'post', $msg_body );
        } catch (FacebookApiException $e) {
        echo $e->getMessage();
      }
    }else{
     $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
     header('Location: ' . $loginUrl);
    }

    //Show sucess message
    if($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/'.$userPageId.'">Visit Your Page</a>';
         echo '</div>';
         echo '</body></html>';
     }
}

?>
4

1 回答 1

3

您不能使用feed端点发布照片。您应该在/me/photos获得publish_stream许可的情况下使用。要发布到相册,您需要/ALBUM_ID/photos端点

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

   $postResult = $facebook->api('/me/photos/','post', $msg_body);

要使用与您的网站无关的网址,您需要使用url

  $msg_body = array(
    'message' => $userMessage,
    'url' => 'http://somepage.com/img.png'
   );
于 2013-02-09T16:01:16.283 回答