How to publish a wall post with 2 pictures - facebook

I'm creating a small app in which people compare diferent pictures of him and his friends.
The app is verry simple and I have no problem with it. The problem comes when users try to publish in their walls. I want the posts to be something like:
I know that by doing something like:
$parameters = array('message' => 'this is my message',
'name' => 'Name of the app',
'caption' => "Caption of the Post",
'link' => 'http://www.link.com',
'description' => 'description',
'picture' => 'http://mysite.com/pic.gif');
$result = $facebook->api('/user_id/feed/', 'post', $parameters );
You can post on a wall, but that limits the app to one picture only and I want the users to be able to post two diferent picures.
Is there a way to publish a post like the one in the image?
EDIT:
Added a picture that might explain what I want in a better way.

Without getting too deep into the Facebook API (since I've never seen a FB app post two photos, I'm guessing it's not possible - most of the apps I see would be as spammy as allowed...), I'd probably start by just compositing the two images (and doing any overlays I wanted to do) at the server side dynamically using something like PHP and the ImageMagick classes.
Then, just feed Facebook the URL to the PHP script that does the compositing, e.g.
$parameters = array('message' => 'this is my message',
'name' => 'Name of the app',
'caption' => "Caption of the Post",
'link' => 'http://www.link.com',
'description' => 'description',
'picture' => 'http://mysite.com/pic.php?pic1_id=1234&pic2_id=2345&favorite=pic1');
$result = $facebook->api('/user_id/feed/', 'post', $parameters );
Of course, I don't know what sort of dimensions Facebook will take for a picture to be posted with a wall post - it might not be wide enough for this to work. I'd try it, though...

Facebook did away with multiple pictures in a post a while ago. When you were able to do it, people were creating "banners" that consisted of multiple pictures side by side. Now only 1 pictured is displayed for any wall post. You can post more pictures, but they won't be sure by default. Facebook will add a "more" link, although they may have done away with that also.

At least in Javascript when using Facebook.streamPublish, as second argument you can give an attachment object that may contain an array of media. Here are the relevant pieces from my app Japan Name:
var media = [];
for (var i = 1; i < syls.length; i++) {
media.push({
'type' : 'image',
'src' : 'http://youarecu.appspot.com/chars/' + syls[i] + '.png',
'href' : streamhref
});
}
...
var attachment = {
'href':'http://apps.facebook.com/youarecute/?from_wall=true&postid=f'+uid+'{{postid}}',
'name':linkedtxt,
'description':txt,
'media':media
};
...
Facebook.streamPublish("", attachment, ...

Related

How to create post with multiple images on fb api? [duplicate]

Now I posting a single photo to wall like this:
$response = $facebook->api("/$group_id/photos", "POST", array(
'access_token=' => $access_token,
'message' => 'This is a test message',
'url' => 'http://d24w6bsrhbeh9d.cloudfront.net/photo/agydwb6_460s.jpg',
)
);
It works fine, but can I somehow post a multiple photos, something like this:
You can now publish multiple images in a single post to your feed or page:
For each photo in the story, upload it unpublished using the {user-id}/photos endpoint with the argument published=false.
You'll get an ID for each photo you upload like this:
{
"id": "10153677042736789"
}
Publish a multi-photo story using the {user-id}/feed endpoint and using the ids returned by uploading a photo
$response = $facebook->api("/me/feed", 'POST',
array(
'access_token=' => $access_token,
'message' => 'Testing multi-photo post!',
'attached_media[0]' => '{"media_fbid":"1002088839996"}',
'attached_media[1]' => '{"media_fbid":"1002088840149"}'
)
);
Source: Publishing a multi-photo story
You can make batch requests as mentioned here: https://stackoverflow.com/a/11025457/1343690
But its simple to loop through your images and publish them directly.
foreach($photos as $photo)
{
//publish photo
}
Edit: (regarding grouping of photos on wall)
This grouping is done by facebook automatically if some photos are uploaded into the same album.
Currently you cannot create an album in a group via Graph API - it is not supported (as of now), see this bug.
But you can do this - create an album manually, then get the album_id by-
\GET /{group-id}/albums, then use the the code with album_id instead of group_id-
foreach($photos as $photo){
$facebook->api("/{album-id}/photos", "POST", array(
'access_token=' => $access_token,
'name' => 'This is a test message',
'url' => $photo
)
);
}
I've tested it, see the result-
Actually you can upload a multi story photo(I did it using Graph Api and PHP) but the problem comes if you need scheduled this post.Your post is schedule but also it shows on the page's feed.
P.S. I'm using Graph Api v2.9
PHP Code
$endpoint = "/".$page_id."/photos";
foreach ($multiple_photos as $file_url):
array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => FALSE,]));
endforeach;
$uploaded_photos = $fb->sendBatchRequest($photos, $page_access_token);
foreach ($uploaded_photos as $photo):
array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->getDecodedBody()['id'].'"}');
endforeach;
$data_post['message'] = $linkData['caption'];
$data_post['published'] = FALSE;
$data_post['scheduled_publish_time'] = $scheduled_publish_time;
$response = $fb->sendRequest('POST', "/".$page_id."/feed", $data_post, $page_access_token);
$post_id = $cresponse->getGraphNode()['id'];
You will need to upload each photo first with published state to false, and then use the ID's of the unpublished photos to the /me/feed endpoint to schedule the photo. The schedule needs to be within the 24 hours from the time the photos are uploaded as facebook deletes all unpublished photos in 24 hours.
Ref:
https://developers.facebook.com/docs/graph-api/photo-uploads/
There is no way to publish more than one photo in the same graph API call.
See documentation: https://developers.facebook.com/docs/graph-api/reference/user/photos

Facebook app post on user's wall low quality image

So I have app, which post image on user's wall. Problem is that, It automatically choose App's image (Page Tab Image 111x74) and add It on user's wall (exapanded). I need to add custom image, not app's page tab image. For now my code:
$photoCaption = 'Text......';
$link = ('https://www.facebook.com/pages/mypage/1555555555?sk=app_1800000000');
# Post Data for Photos API
$post_data = array(
'message' => $photoCaption,
'link' => $link,
'caption' => 'This is captions!'
);
$apiResponse = $facebook->api('/me/feed', 'POST', $post_data);
You post photos with /me/photos, not /me/feed, hereĀ“s the information you need including example code:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/photos

post on Facebook page big photo

I have read quite a few posts about posting photos on FB (fan)page but none really answer my question.
I am using a correct call to the FB SDK to post on my page as you see the last post where there is a thumbnail photo and a few pieces of text including a link.
$attachment = array('access_token' => $FB_Token, 'message' => $FB_AppMsg,'name' => $FB_AppTitle,'link' => $FB_AppURL,'description' => $FB_AppResume),'picture'=> $FB_AppImage,
'actions' => json_encode(array('name' => $FB_AppActionName,'link' => $FB_AppActionLink)));
$status = $facebook->api("/".$FB_PageName."/feed", "POST", $attachment);
Instead of a thumbnail image, I want an image of the width of 1 or 2 column (as you will see down the timeline), and a text message that can include a link to my blog on my website.
How can I achieve this easily ?

Facebooks Link preview

I've searched and searched and searched and cannot find a way for a person to post a link on a page from an app (As the page owner, of course), and have a link preview. It just posts the link instead of a preview like it would if you were posting via facebook. I would like to know if there is a way to override the link preview like this:
$x = $facebook->api('/'.$_POST["id"].'/link', 'post', array('message'=> urldecode($_POST["message"]), 'access_token' => $_POST["auth"], 'cb' => '', 'picture' => 'url to pic','description'=>'blah blah'));
Please help, don't really know what else to do..
Consider using a link shorter service that allows customization of link preview. With linkfork.co you can customize the image, title, and description.
I did a lot of testing and came up with my answer:
$x = $facebook->api('/'.$_POST["id"].'/links', 'post', array('link' => $url,'caption' => $data['description'],'name' => $data['title'],'picture' => $data['thumbnail_url'],'url' => $url, 'message'=> urldecode($_POST["message"]), 'access_token' => $_POST["auth"], 'cb' => ''));

How to include html in stream.Publish

I'm using the old Rest API (and old Javascript SDK) to develop an iframe application inside facebook.
However I would like to have the wall posts (calling stream.Publish) to include new lines and having people's names with links to their profiles. However every time I include html content, FB strips it.. but I know it can be done, because some apps do it, for example:
http://img.skitch.com/20100702-jhqradpi3td4d53sdb3qin92sb.png
Cheers,
Ze
You cannot have arbitrary HTML in a wall post. If it looks like HTML, Facebook will strip it. The only other alteration Facebook will do I believe is convert text that looks like links into links (so if you have http://www.google.com somewhere in the message, Facebook will automatically turn it into a link).
However Facebook does provide basic facilities for including basic things like a picture, caption, description, link, etc through stream.publish by passing in additional parameters. This is an example for including a few of these things from Facebook's documentation (http://wiki.developers.facebook.com/index.php/Stream.publish):
$message = 'Check out this cute pic.';
$attachment = array(
'name' => 'i\'m bursting with joy',
'href' => 'http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/',
'caption' => '{*actor*} rated the lolcat 5 stars',
'description' => 'a funny looking cat',
'properties' => array('category' => array(
'text' => 'humor',
'href' => 'http://www.icanhascheezburger.com/category/humor'),
'ratings' => '5 stars'),
'media' => array(array('type' => 'image',
'src' => 'http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg',
'href' => 'http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/')),
'latitude' => '41.4', //Let's add some custom metadata in the form of key/value pairs
'longitude' => '2.19');
$action_links = array(
array('text' => 'Recaption this',
'href' => 'http://mine.icanhascheezburger.com/default.aspx?tiid=1192742&recap=1#step2'));
$attachment = json_encode($attachment);
$action_links = json_encode($action_links);
$facebook->api_client->stream_publish($message, $attachment, $action_links);
Check this out for more info on what attachments you can include.