s_p
s_p

Reputation: 4693

facebook graph api - post large image

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'));
}
?>

Upvotes: 0

Views: 4750

Answers (1)

Lix
Lix

Reputation: 47966

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);

Upvotes: 1

Related Questions