0

I finally got facebooks graph api to post messages on my fan PAGE as page
How do i get it to post large images as a post, not as a link?

'source' => $photo seems to create a thumbnail

this is what i have so far

<?php

$page_id = 'YOUR-PAGE-ID';
$message = "I'm a Page!";
$photo = "http://www.urlToMyImage.com/pic.jpg";

require '../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
    'appId'  => 'YOUR-APP-ID',
    'secret' => 'YOUR-SECRET-ID',
));


$user = $facebook->getUser();

if ($user) {
    try {
        $page_info = $facebook->api("/$page_id/?fields=access_token");
        if( !empty($page_info['access_token']) ) {
                $facebook->setFileUploadSupport(true); // very important
                $args = array(
                        'access_token'  => $page_info['access_token'],
                        'message'       => $message,
                        'source'        => $photo

                );
                $post_id = $facebook->api("/$page_id/feed","post",$args);
        }
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
    $logoutUrl = $facebook->getLogoutUrl(array( 'next' => 'http://mydomain.com/logout_page.php' ));
} else {
    $loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
}
?>
t q
  • 4,593
  • 8
  • 56
  • 91

1 Answers1

1

The problem here is that you are in actual fact not posting a photo. What you are doing is posting a link to that photo so what you see is indeed a thumbnail preview image that Facebook retrieved from that URL.

What you'll want to do is provide a full path to a file on your server prefixed with the @ symbol. The topic has been discussed on the site quite a bit so I'll just point you in the direction of a canonical post dealing with uploading of images to Facebook with the PHP SDK

Upload Photo To Album with Facebook's Graph API

The code looks like this -

$facebook->setFileUploadSupport(true);
$params = array('message' => 'Photo Message');
$params['image'] = '@' . realpath($FILE_PATH);
$data = $facebook->api('/me/photos', 'post', $params);
Community
  • 1
  • 1
Lix
  • 47,311
  • 12
  • 103
  • 131
  • That all depends on the access token you use. The syntax is identical - except of course `/me` turns into the `/PAGE_ID` - but the access_token is what dictates on behalf of whom the request is being made. – Lix Jul 16 '12 at 21:19
  • it worked when i had `feed` but now that it is `photos` it doesnt work – t q Jul 16 '12 at 21:24
  • 1
    Ok - looks like you are going to need the page's album_id... So you use the same call only to `/ALBUM_ID` with the page token and it should work... – Lix Jul 16 '12 at 21:26