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!'
));
Related
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)
));
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.
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
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
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/