Posting picture to Facebook wall via POST object not appearing - facebook

I'm trying to post a picture with publish_stream permissions from my site onto Facebook. For some reason, the picture doesn't show up when I post but everything else works fine.
By accessing http://www.mysite.com/image/questions.png, the picture shows up correctly. Am I missing something?
$body = array(
'name' => 'Join this site',
'message' => '',
'description' => 'Check this out',
'picture' => 'http://www.mysite.com/image/questions.png',
'link' => SITE_URL,
);
$batchPost = array();
Then I batch post.

Double check to see if it really works.
$body = array(
'name' => 'Join this site',
'message' => '',
'description' => 'Check this out',
'picture' => 'http://www.mysite.com/image/questions.png',
'link' => SITE_URL,
);
$batchPost = array();
$status = $facebook->api('/me/feed', 'POST', $body);
if (isset($status['id'])) //Add a check
{
echo "Message posted to wall!";
}
If not you can use JavaScript SDK FB.ui method to post to Facebook Wall. It is more flexible in my opinion as users can input their own message, unlike how it is defined by the developer through the PHP SDK method.
JavaScript SDK FB.ui Method
<script>
function postToWall()
{
var obj = {
method: "feed",
name: "Join this site",
description: "Check this out",
caption: "CAPTION",
picture: "http://www.mysite.com/image/questions.png",
link: "SITE_URL"
};
function callback(response) {
//do something
}
FB.ui(obj, callback);
}
</script>
More on JavaScript SDK Feed Dialog: http://developers.facebook.com/docs/reference/dialogs/feed/
Edit: Use another image and try again. http://www.mysite.com/image/questions.png has been removed. Upload your picture on some image hosting website instead of hotlinking the image directly.

Related

How to Post on FB app users wall through API code

I have created a facebook app and need to post on all users FB WAll, who have authorized app to post on there behalf.
i.e, A new event organized somewhere, So through App, admin can post on every App Users FB Wall about the event.
I was using Graph API, however its not working.
Any Pointers/ Guidance will be highly appreciated.
Thanks
You have to do an api call with parameters to post on the users wall.
Edit.:
Here is the below linked example, with some explanation:
<?php
$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'
);
?>
$result = $facebook->api('/me/feed/', 'post', $attachment);
The $attachment array contains the parameters of the wall post and the $facebook->api('/me/feed/','post',$attachment); make the call and returns the result into $result.
Here you can find the source: How do you post to the wall on a facebook page (not profile)
Publishing to user's wall in JS SDK:
var body = 'Status Test';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
[EDIT]
In Php
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'message' => 'Posting with the PHP SDK!'
));

Posting to Facebook as Links instead of Posting as Facebook Objects using Facebook PHP SDK

I am trying to use the Graph API to post on the wall of the authenticated user.
The issue which I am facing is when I try to share a post e.g.
http://www.facebook.com/surendrakumar.in/posts/486644641373819
using Graph API to the users feed
$story_url = "http://www.facebook.com/surendrakumar.in/posts/486644641373819"
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'access_token' => $fb_access_token,
'link' => $story_url,
'message' => ($msg != "" ? $msg : "")
));
Then the post which is getting shared in the Facebook is only a link, which is not expected.
Expected :
Post on the wall with http://www.facebook.com/surendrakumar.in/posts/486644641373819 link and details of the post, preview etc.
Actual:
Only a link is posted. no preview, and any other information.
Put the link within the message text.
I.E.:
$story_url = "http://www.facebook.com/surendrakumar.in/posts/486644641373819"
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'access_token' => $fb_access_token,
'message' => ($msg != "" ? $msg."\n".$story_url : "".$story_url)
));

PHP SDK: Post to FB application's wall as the app itself

There are a lot of questions on SO about this, but not exactly what I am looking for.
In my case, users can log in through Facebook/Twitter/other. And they can upload an image.
Once they upload an image, two things will happen. The FB user's status is updated with an attachment to the link. And on the FB App's wall, a status update is also posted but by the application itself and not by the user. I am having trouble with this last part. So the user does not have to be logged in through Facebook for this latter to occur.
My code:
$facebook = new Facebook($config);
$attachment = array(
'message' => 'A user just posted a new item',
'name' => $tag,
'caption' => $desc,
'link' => WEBURL,
'description' => '',
'picture' => $img,
'actions' => array(array('name' => 'Go to item',
'link' => WEBURL))
);
$facebook->api('/'.PAGEID.'/feed', 'POST', $attachment);
An application's wall behaves exactly like a page's wall or a user's wall. Lookup the documentation for those.

Facebook offline wall posting

I do have website for Restaraunt which has facebook registration module for the users to register. There are two kinds of user for my website, one is normal registered user and second user is Facebook Registered user. This seems to work correctly upto this moment.In the website, all the users are allowed to post their own review about hotels,favorites etc.
I need a way for automatic sharing of reviews, likes and favourites to the users Facebook wall in the Facebook website by using there Fb details(Fbid) that i have stored in my database. Each the reviews need to be posted to the FB wall using his/her own fb-id without fb login. Is there is any php-Facebook plugin /JSSDK to meet this requirement?
I have used the following lines of library codes, but nothing happend yet now.
require_once 'facebook.php';
$api_key = 'yyyyyyyyyyyyyyyyyyy';
$secret = 'xxxxxxxxxxxxxxxxxxxx';
$name = 'Publish feed code example';
$id='100001948358224';
$name_href = 'http://forum.developers.facebook.com/viewtopic.php?id=44721';
$caption = 'A simple code caption text';
$description = 'The new Facebook.streamPublish code to pop up a publish feed form';
$img_1 = 'http://www.applications.junkieyard.com/fbfgsfy/images/smileys/smiley-09-05.png';
$img_1_href = 'http://apps.facebook.com/fbfgsfy/profile.php';
$action_links_text = 'Facebook?';
$action_links_href = 'http://www.facebook.com/';
$attachment = array('name' => $name, 'href' => $name_href, 'caption' => $caption, 'description' => $description, 'media' => array(array('type' => 'image', 'src' => $img_1, 'href' => $img_1_href)));
$action_links = array(array('text' => $action_links_text, 'href' => $action_links_href));
if ($id) {
$target_id = $id;
?>
<script>
var message = "";
var attachment = <?=json_encode($attachment)?>;
var action_links = <?=json_encode($action_links)?>;
var target_id = <?=$target_id?>;
alert(Facebook.streamPublish(message, attachment, action_links, target_id));
</script>
<?php
}
?>
offline_access is no longer used in facebook, the new way is the Expiration Time of the TOKEN through New Endpoint
read more at https://developers.facebook.com/roadmap/offline-access-removal/
You would need to request the publish_stream and offline_access permissions from the user to post on their wall when their session is not active.
To post on their wall programmatically, use the feed method of FB.ui
FB.ui(
{
method: 'feed',
name: 'Restaurant App',
link: 'http://apps.facebook.com/yourapp',
caption: 'Check out my review',
description: 'The most awesome restaurant ever.',
message: 'Check out this awesome app'
},
function(response) {
console.log(response);
console.log(response.post_id);
if (response && response.post_id) {
console.log('Post was published.');
} else {
console.log('Post was not published.');
}
}
);
To see the above code in action, check it out on the demo app FBRell

facebook application post on user's wall with permission(publish/skip) php sdk

i am creating a facebook application. i have managed an extended publish stream application. and i want to display the app results on user's wall. doing the method below, it automatically posts on the user's wall, i want to do it through the publish/skip dialog. could anyone please help me. thanks a lot!!
$facebook->api('/me/feed', 'post', array(
'message' => message,
'name' => $fbme['first_name'],
'description' => 'here goes description',
'caption' => 'this is caption',
'picture' => $imageurl,
'link' => 'some link here',
//the next part, inviting friends. i want when the user clicks publish/skip only then a dialog window to apper to request to invite friends. i try it this way, but it does not work.
function(response) {
if (response && response.post_id) {
alert('Post was published.');
'<?php echo("invitefriends.php")'
} else {
alert('Post was not published.');
'<?php echo("invitefriends.php")'
}
the problem i have is i get three windows and all of them simultaneously. invitefriends.php has the same code as mentioned in the javascript sdk example and it works fine.
let me know where and how to include invitefriends.php.
thanks!!
You should use FB.ui:
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
message: 'Facebook Dialogs are easy!'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
To test this, go to the Test Console -> Click on the Examples -> And then from the fb.ui list choose feed.
For this you can use FB's JS API
You can follow this tutorial
http://thinkdiff.net/facebook/graph-api-iframe-base-facebook-application-development/
I am not sure but you as long as i can guess you need access token to post on user wall.
$token = $facebook->getAccesstoken();
$facebook->api('/me/feed', 'post', array(
'message' => message,
'name' => $fbme['first_name'],
'description' => 'here goes description',
'caption' => 'this is caption',
'picture' => $imageurl,
'link' => 'some link here',
'access_token' =>$toekn);
i hope it