Facebook offline wall posting - facebook

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

Related

Auto post facebook fan page with fan page name PHP SDK 3.2.2

I have used this code for auto post on my facebook fan page
<?php
// Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/
require ('facebook.php');
define('FACEBOOK_APP_ID',"YOUR-APP-ID");
define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET");
$user = null;
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
$user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.
if($user == 0) {
/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*/
$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));
echo ("<script> top.location.href='".$login_url."'</script>");
} else {
try {
$params = array(
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png",
);
$post = $facebook->api("/$user/feed","POST",$params);
echo "Your post was successfully posted to UID: $user";
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
}
?>
But I need to post on my facebook fan page with my fan page name, this scrpit work so good but this code post on my fan page with my admin account and not like my fan page.
PLZ HELP ME :(
I think you need to take a look to this article carefully, I did it using the steps mentioned there.
Just put you token here:
https://graph.facebook.com/me/accounts?access_token=token
Then you will find the access token for posting as a page.
Hope that helps.

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 picture to Facebook wall via POST object not appearing

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.

Facebook stream publish to wall as App/Page

i wonder if it is possible to post to a users stream/wall by using stream_publish as a page or an app. Currently I've granted my app to stream_publish on my own wall. But when I post to my stream from the app the post is displayed like I would've posted it by myself instead of having the app posted it to my wall.
I want to have the post looks like the app posted it. I already used the uid-parameter in the stream_publish params and set it to the appId ... but the post still looks like an own post.
my code:
$postData = array( $feed_dir = '/'.$fb_uid.'/feed/',
$method = 'POST',
$msg_body = array( 'access_token' => $arrUserData['access_token'],
'message' => 'here goes the message',
'name' => '-name-',
'link' => 'http://some-url',
'description' => '-description-',
'actions' => ($actions),
'uid' => $iniHandler->getIniSetting('facebook.app.id')
)
);
try {
$res = $facebook->api($feed_dir, $method, $msg_body);
}
catch (Exception $e) {
$err_str = $e->getMessage();
}
Or is ther another way to post to a wall and let the post looks like a post by an app? My users can sign up for issues in my app and my app posts some news to the users wall ... thats my aim.
You also need manage_pages permissions. Once you have those, HTTP Get me/accounts and that will be a list of pages that the logged in user is admin of. In that list will be a unique page access_token. Use that token to http post a new wall/stream item.

How do you post to the wall on a facebook page (not profile)

I have a blog site written in php and it posts new blog posts to twitter and a blog ping automatically under the hood using simple http post requests passed using php curl.
I have a facebook page for the blog site and want the updates to be posted to the wall on the page, is there a simple way to do this?
What I really want is a url and set of params to parcel up as an http post request.
Note that this is to post to the wall on a new style page not a profile.
Get PHP SDK from github and run the following code:
<?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',
'actions' => array(
array(
'name' => 'Get Search',
'link' => 'http://www.google.com'
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
the above code will Post the message on to your wall... and if you want to post onto your friends or others wall then replace me with the Facebook User Id of that user..for further information look out the API Documentation.
This works for me:
try {
$statusUpdate = $facebook->api('/me/feed', 'post',
array('name'=>'My APP on Facebook','message'=> 'I am here working',
'privacy'=> array('value'=>'CUSTOM','friends'=>'SELF'),
'description'=>'testing my description',
'picture'=>'https://fbcdn-photos-a.akamaihd.net/mypicture.gif',
'caption'=>'apps.facebook.com/myapp','link'=>'http://apps.facebook.com/myapp'));
} catch (FacebookApiException $e) {
d($e);
}
Harish has the answer here - except you need to request manage_pages permission when authenticating and then using the page-id instead of me when posting....
$result = $facebook->api('page-id/feed/','post',$attachment);
You can not post to Facebook walls automatically without creating an application and using the templated feed publisher as Frank pointed out.
The only thing you can do is use the 'share' widgets that they provide, which require user interaction.
If your blog outputs an RSS feed you can use Facebook's "RSS Graffiti" application to post that feed to your wall in Facebook. There are other RSS Facebook apps as well; just search "Facebook for RSS apps"...
You can make api calls by choosing the HTTP method and setting optional parameters:
$facebook->api('/me/feed/', 'post', array(
'message' => 'I want to display this message on my wall'
));
Submit Post to Facebook Wall :
Include the fbConfig.php file to connect Facebook API and get the
access token.
Post message, name, link, description, and the picture will be submitted to Facebook wall.
Post submission status will be shown.
If FB access token ($accessToken) is not available, the Facebook Login
URL will be generated and the user would be redirected to the FB login
page.
Post to facebook wall php sdk
<?php
//Include FB config file
require_once 'fbConfig.php';
if(isset($accessToken)){
if(isset($_SESSION['facebook_access_token'])){
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}else{
// Put short-lived access token in session
$_SESSION['facebook_access_token'] = (string) $accessToken;
// OAuth 2.0 client handler helps to manage access tokens
$oAuth2Client = $fb->getOAuth2Client();
// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
// Set default access token to be used in script
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}
//FB post content
$message = 'Test message from CodexWorld.com website';
$title = 'Post From Website';
$link = 'http://www.codexworld.com/';
$description = 'CodexWorld is a programming blog.';
$picture = 'http://www.codexworld.com/wp-content/uploads/2015/12/www-codexworld-com-programming-blog.png';
$attachment = array(
'message' => $message,
'name' => $title,
'link' => $link,
'description' => $description,
'picture'=>$picture,
);
try{
//Post to Facebook
$fb->post('/me/feed', $attachment, $accessToken);
//Display post submission status
echo 'The post was submitted successfully to Facebook timeline.';
}catch(FacebookResponseException $e){
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}catch(FacebookSDKException $e){
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
}else{
//Get FB login URL
$fbLoginURL = $helper->getLoginUrl($redirectURL, $fbPermissions);
//Redirect to FB login
header("Location:".$fbLoginURL);
}
Refrences:
https://github.com/facebookarchive/facebook-php-sdk
https://developers.facebook.com/docs/pages/publishing/
https://developers.facebook.com/docs/php/gettingstarted
http://www.pontikis.net/blog/auto_post_on_facebook_with_php
https://www.codexworld.com/post-to-facebook-wall-from-website-php-sdk/