Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用应用程序在粉丝页面上发布Facebook图片_Php_Facebook_Api - Fatal编程技术网

Php 使用应用程序在粉丝页面上发布Facebook图片

Php 使用应用程序在粉丝页面上发布Facebook图片,php,facebook,api,Php,Facebook,Api,我需要在facebook粉丝页面上发布应用程序。 我的帖子类型是文本+图像。 当我只发布文本时,我没有问题,但当我尝试添加jpg时,它不起作用 这是我的密码: <pre> <?php require_once 'facebook.php'; // configuration $appid = 'XXX'; $appsecret = 'YYY'; $pageId = 'ZZZ'; $msg = 'MSG MSG MSG'; $title = 'TITOLO TITOLO TIT

我需要在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);
?>


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

尝试以下操作:


我在代码中发布的图片是:$photo_details['Picture']='@'。realpath('aaa.jpg');它位于应用程序的index.php的同一文件夹中。我没有使用$pic='';(以前用于尝试使用外部jpg)如果我使用echo realpath('aaa.jpg');我得到/var/www/html/fb/aaa.jpgit非常适合在我的墙上发布,但我需要在粉丝页面上发布(我是管理员)…我应该替换什么吗?好的,刚刚在相册创建中添加了'access\u token'=>$page\u info['access\u token',现在它可以按照我的需要工作了。谢谢!
//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);