Arun Nair
Arun Nair

Reputation: 13

Upload Facebook photos on page timeline (PHP)

I have a cache of pictures in my website, and I need to upload these photos to my Facebook fan page 4-5 times a day. My code creates an album and also uploads the photos to the album, however, these photos do not appear in the timeline.

So my question is, how do I upload photos to my fan page such that they appear on the timeline, on the wall. The language in use is PHP

Any help is greatly appreciated.

Thanks

Edit 1: Here is the code:

<?php   
require 'facebook.php';
$facebook = new Facebook(array(
    'appId'  => "AAAAAAAAAA",
    'secret' => "BBBBBBBBBB",
));

$fanpage_token = "ZZZZZZZZZZZZZZZZZZZZZZZZZZ";

$facebook->setFileUploadSupport(true);

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

$album_uid = $create_album['id'];

echo $album_uid;

 $img = '7newx.jpg';
  $args = array(
   'message' => 'Random message',
   'image' => '@' . $img,
   'aid' => $album_uid,
   'no_story' => 1,
   'access_token' => $fanpage_token
  );

  $photo = $facebook->api($album_uid . '/photos', 'post', $args);

?>

Upvotes: 1

Views: 2601

Answers (1)

Relaxing In Cyprus
Relaxing In Cyprus

Reputation: 2006

Ok, so I guess you tried removing the no_story and found that it didn't affect the timeline. Thats what I found too.

What you have to do is make another post, but this time, as a link. You need to use your array $photo, which was returned from your first post. If you examine that you should see it has a single element called ['id'], containing the id of your uploaded photo.

You need to turn that into a link that facebook would use to display. This is simple.

if (isset($photo['id']))
{
$message = "My latest photo";
$link = "https://www.facebook.com/photo.php?fbid=".$photo['id'];
$attachment = array
(
'access_token'=>$fanPageAccessToken,
'type' => 'photo',
'message' => $message,
'link' => $link 
);

$result = $facebook->api($fanPageId.'/links/','post',$attachment);
}

I am assuming you can work out what $fanPageAccessToken and $fanPageId are.

If you do that, you should get what you want.

Upvotes: 5

Related Questions