Emperola.com
Emperola.com

Reputation: 31

When posting image using PHP to Facebook wall only thumbnail is displayed

When publishing picture to my FB page as an Admin using PHP, it appears as a thumbnail. I would like to appear it as full size picture

Code I'm using:

$page_info = $facebook->api("/$page_id?fields=access_token");
$page_access_token = $page_info['access_token'];

$data['picture'] = "image.jpg";
$data['link'] = "link";
$data['message'] = "message";
$data['access_token'] = $page_access_token;

$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);

Any help?

Here is How I would like it to be displayed - https://i.sstatic.net/0PUOS.png

Thank you


Thank you for the answers,

I tried remove the link but it didn't work. I searched more and tried the following code, but it gives me error >>>

Warning: curl_setopt_array() [function.curl-setopt-array]: open_basedir restriction in effect. File() is not within the allowed path(s): (/data/web/virtuals/17535/virtual) in /data/web/virtuals/17535/virtual/www/apps/fb/src/base_facebook.php on line 963 Fatal error: Uncaught CurlException: 3: No URL set! thrown in /data/web/virtuals/17535/virtual/www/apps/fb/src/base_facebook.php on line 994

require 'facebook.php';
$facebook = new Facebook(array(
'appId'  => '111111111111',
'secret' => '222222222222222222',
   'fileUpload' => true
));

$page_id = '3333333333333';
$page_info = $facebook->api("/$page_id?fields=access_token");
$page_access_token = $page_info['access_token'];     

$image = "http://www.emperola.com/upload-01/18001-img_hero.jpg";

$args = array(
        'access_token'  => $page_access_token,
        'message'       => 'message',
        'name'          => 'Title',
        'picture'       => $image
    );

    $post_id = $facebook->api("/$page_id/feed","post",$args);

Thank you for your help

Upvotes: 1

Views: 1448

Answers (2)

Emperola.com
Emperola.com

Reputation: 31

Thank you all for your help,

following code works for me as expected:

$page_info = $facebook->api("/$page_id?fields=access_token");
$page_access_token = $page_info['access_token'];      
$image = "../$upload/$picture";
$args = array(  
    'message' => ''.$nazev.' - '.$link.'',  
    'access_token' => $page_access_token,  
    'image' => '@' . realpath($image)
);  
$data = $facebook->api('/'.$page_id.'/photos', 'post', $args);

Upvotes: 1

Steven V
Steven V

Reputation: 16595

Currently, you're telling Facebook your post is a link. You need to modify it so it isn't a link, and more like a "status update". Try removing the "link" property from your API call to Facebook and adding the URL to the message. If that doesn't work, as @CRroe said in a comment, you'll need to upload the image to Facebook using the API, then share that photo on the page/user timeline.

Upvotes: 0

Related Questions