Facebook development - post link with photo - php

I'm building an app for facebook. I need to post some link, standard code works correctly:
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'Mylink',
'message' => 'Posting with the PHP SDK!',
But I need to attach the photo also. It works if photo is on the link I post, but I don't want that photo to appear on that page.
Is there any way?

Simply add a parameter, picture to while making the call-
array(
'link' => 'Mylink',
'message' => 'Posting with the PHP SDK!',
'picture' => '{image-link}'

Related

Facebook 'caption' option not showing up for non-timeline Facebook

So I'm creating posts to the facebook user's wall using Graph API
I'm referring to the 'caption' as stated here:
http://nocturnsoft.com/devblog/?p=906
when I specified the 'caption' option, the text in the caption would appear properly for profiles that uses the timeline, but for profile that use the old style, the caption would not appear...
Am I doing something wrong here or is this how it's supposed to be....If it is how it's supposed to be, how would I display text beneath the link for the Facebook post for non timeline profiles
btw: I'm using Facebook PHP SDK
In my apps the post data array looks like this and the caption (message) is present on both new and old profiles.
/* post to fb */
$post = array(
'access_token' => $fb_access_token,
'message' => 'THIS IS YOUR CAPTION HERE',
'link' => 'LINK TO YOUR SITE OR APP HERE',
'picture' => 'URL TO IMAGE HERE',
'name' => 'APP NAME HERE',
'description' => 'AWESOME DESCRIPTION ABOUT YOUR APP GOES RIGHT HERE!'
);
$res = $facebook->api('/me/feed', 'POST', $post);
Hope this helps. If so don't forget to say so! :)

Facebook php sdk - post to a wall with prompt

T'm writing a Facebook canvas app, and I'm trying to post to the user's wall. this the code I'm using:
if ($user) {
$attachment = array('message' => 'This is message',
'name' => 'Name of the message',
'caption' => 'Caption of link',
'link' => 'http://www.example.com/about',
'description' => 'Great site!',
'picture' => 'http://lorempixum.com/100/100/',
'actions' => array(array('name' => 'Do Something!',
'link' => 'http://www.example.com'))
);
$result = $facebook->api('/me/feed/',
'post',
$attachment);
}
So I tested with 2 facebook accounts, and it posts to the wall but without the facebook dialog i'm always seeing. I would like the user to be warned that I'm gonna post on the wall, and allow him to cancel it.
How do I do that?
You need to use the JavaScript SDK, essentially the dialogs bit: http://developers.facebook.com/docs/reference/dialogs/feed/

facebook wall post no image

I am adding functionality to post to a visitors Facebook wall.
I am using the following code:
$path_to_image = "http://projects.kleelof.com/boot_designer/image_interchange.php?c=" . $file_id;
$attachment = array('message' => 'this is my message',
'name' => 'The name of your company',
'caption' => "Caption of the Post",
'link' => $path_to_image,
'picture' => $path_to_image,
'description' => 'this is a description',
'access_token' => $facebook->getAccessToken()
);
//echo($path_to_image);
$result = $facebook->api('/me/feed/','post',$attachment);
The post appears on my wall, but not the image.
You can see the full process and post it makes by trying the app at: http://projects.kleelof.com/boot_designer - Then select either one of the 2 links.
take care,
lee
I think the path to the image needs to be and actual file system path, and the image will be read and uploaded along with the request for FB to process. Also, it needs to start with a # to actually upload it.

Looking for image attachment php API feeds for stream.publish

I am desperately looking for image attachment php api feeds for my facebook app.
Basically what I am trying to do is send an image attachment, along with an automatic "post to friends wall" action.
The idea behind it is that a user sends a "virtual burger" to their friends wall, with a message offering them a discount.
This is a snippet of the code that successfully sends the message, but I can't get the attachment to work.
if($_REQUEST['friend_1']!='' && $_REQUEST['friend_1']!="Start typing a friend's name") {
try {
$fql1 = "select name from user where uid=" . $_REQUEST['friend_1'];
$param1 = array(
'method' => 'fql.query',
'query' => $fql1,
'callback' => ''
);
$fqlResult1 = $facebook->api($param1);
$friend_1_name = $fqlResult1[0]['name'];
$statusUpdate = $facebook->api('/'.$_REQUEST['friend_1'].'/feed', 'post', array('link' => $fanpageURL, 'name' => 'Have a virtual Unity Burger.', 'description' => " ".$user_name." just sent you a virtual Unity Burger. If you would rather have the real thing then come add your name on the Unity list and we will give you a 20% discount on your next visit and an exclusive Unity keyring.", 'properties' => '', 'cb' => ''));
} catch (FacebookApiException $e) {
//echo "Notification not send to user ".$fqlResult1[0]['name']."<br>";
I think there are two ways to attach an image to a wall post.
The first one is to define the meta og:image in the target page and post the link to the friends wall. Facebook will query the target and grab the Open Graph info displaying it in the wall. You can test this with the Facebook Debugger.
The meta property should look like this:
<meta property="og:image" content="http://url.to/image" />
You can also define other Open Graph properties like title, description, etc.
The second way to attach the image to the post is to include the picture parameter in the Graph API call. In your code you only define some parameters (link, name, description...) but you can also send picture, caption, message...
So your API call could be like this:
$params = array( 'access_token' => '',
'message' => '',
'link' => '',
'picture' => '',
'name' => '',
'caption' => '',
'description' => ''
);
$wallPost = $facebook->api('/'.$to.'/feed', 'post', $params);

Posting on friend's wall

How do I post to friend's wall using PHP Graph API? I got some javascript solutions. But I need PHP ones. Thank you.
Check the documentation here http://developers.facebook.com/docs/reference/api/post/.
Try $facebook->api('/Friend_ID/feed','post',array('message'=$message));. Refer to the documention for more parameters.
it requires few things
Create a Facebook Application: FB Documentation
Request extended permissions to access a user's photos and their friend's photos Facebook Auth / Permissions
FQL + JSDK to request the data JSDK Doc
$attachment = array('message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://mylink.com',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$result = $facebook->api('/me/feed/',
'post',
$attachment);
good luck

Categories