1

我需要使用应用程序在 Facebook 粉丝页面上发帖。我的帖子类型是文字+图片。当我只发布文本时,我没有问题,但是当我尝试添加 jpg 时它不起作用。

这是我的代码:

<pre>
<?php
require_once 'facebook.php';

// configuration
$appid = 'XXX';
$appsecret = 'YYY';
$pageId = 'ZZZ';
$msg = 'MSG MSG MSG';
$title = 'TITOLO TITOLO TITOLO';
$uri = 'http://www.google.it/';
$desc = 'Description';
$pic = 'http://sharefavoritebibleverses.com/images/bible_verses.png';
$action_name = 'AZIONE NOME';
$action_link = 'http://www.yahoo.it';

$facebook = new Facebook(array(
     'appId' => $appid,
     'secret' => $appsecret,
     'cookie' => false,
));

$user = $facebook->getUser();

// Contact Facebook and get token
if ($user) 
{
// you're logged in, and we'll get user acces token for posting on the wall
     try 
     {
          $facebook->setFileUploadSupport(true);
          $page_info = $facebook->api("/$pageId?fields=access_token");
          if (!empty($page_info['access_token'])) {
          /*$attachment = array(
               'access_token' => $page_info['access_token'],
               'message' => $msg,
               'name' => $title,
               'picture'=>$pic
               );*/
          $photo_details = array(
               'message'        => 'message',
               'access_token'   => 'XYZ'
               );
               $photo_details['picture'] = '@'.realpath('aaa.jpg');
               echo realpath('aaa.jpg');

               $status = $facebook->api("/$pageId/feed", "post", $photo_details);
               } 
               else 
               {
                    $status = 'No access token recieved';
               }
          } 
          catch (FacebookApiException $e) 
          {
               error_log($e);
               $user = null;
          }
} 
else 
{
     // you're not logged in, the application will try to log in to get a access token
     header("Location:{$facebook->getLoginUrl(array('scope' => 'photo_upload,user_status,publish_stream,user_photos,manage_pages'))}");
}

echo $status;
echo "<br>CONT=".count($status);
?>

我也需要像第二种格式,而不是第一种格式:

在此处输入图像描述

我的代码有什么问题?

谢谢!

4

2 回答 2

0

尝试这个:

//At the time of writing it is necessary to enable upload support in the Facebook SDK, you do this with the line:
$facebook->setFileUploadSupport(true);

//Create an album
$album_details = array(
        'message'=> 'Album desc',
        'name'=> 'Album name'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);

//Get album ID of the album you've just created
$album_uid = $create_album['id'];

//Upload a photo to album of ID...
$photo_details = array(
    'message'=> 'Photo message'
);
$file='app.jpg'; //Example image file
$photo_details['image'] = '@' . realpath($file);

$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
于 2013-05-16T12:17:34.493 回答
0

请尝试确保 $pic 是您服务器上的相对图像位置,而不是图像的通用网址。

于 2013-05-16T11:35:36.950 回答