How to post simple text to FB wall programmatically using HTML? - facebook

What I'd like to do is to post some simple text to a user's FB wall (with the user's ID already known to my app).
Have read quite a few posts about posting to FB wall, however, still stumbled.
From the sample code at a youtube video, I created a complete code set and posted to
FB dev forum, the err msg I get is,
"FB.getLoginStatus() called before calling FB.init()"
Here's the link of my code,
http://forum.developers.facebook.net/viewtopic.php?id=94801
Note:
We could use a simple HTML page for testing this...
What's wrong? Thanks.

Here's the source from my project's facebook test page, containing complete implementations of a few common facebook tasks. The only thing redacted is the facebook app ID. Obviously, you don't have our libs but in this case they just verify the session and draw headers.
<html>
<head>
<meta charset="UTF-8" />
<title>phyre Lux Client</title>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.5.custom.min.js"></script>
<script type="text/javascript" src="../phyrelib-clientside.js"></script>
<link type="text/css" href="../css/custom-theme/jquery-ui-1.8.5.custom.css" rel="stylesheet">
<link type="text/css" href="../css/phyre.css" rel="stylesheet">
<script src="js/typeface.js"></script>
<script src="js/cicle_fina.typeface.js"></script>
</head>
<body onLoad='return 0;' id='luxDocBody' class='phyremodule'>
<div id='fb-root'></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type='text/javascript'>
FB.init({appId: 'REDACTED', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
alert('yay');
} else {
// The user has logged out, and the cookie has been cleared
alert('nay');
}
});
FB.ui(
{
method: 'stream.publish',
message: 'getting educated about Facebook Connect',
attachment: {
name: 'Connect',
caption: 'The Facebook Connect JavaScript SDK',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
href: 'http://github.com/facebook/connect-js'
},
action_links: [
{ text: 'Code', href: 'http://github.com/facebook/connect-js' }
],
user_message_prompt: 'Share your thoughts about Connect'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
alert('yay');
} else {
// no user session available, someone you dont know
alert('nay');
}
});
</script>
<fb:login-button></fb:login-button>
</body>
</html>

Related

Facebook dialog feed, doesnt post to friend wall. JavaScript sdk

Im trying to post to a facebook friend wall after a friend is selected.
Im using friend's selector from https://codersgrave.com/
I have this code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Facebook Friend Selector Basic Example - Coders' Grave</title>
<!-- Add Facebook Friend Selector CSS -->
<link type="text/css" href="friend-selector/jquery.friend.selector-1.2.1.css" rel="stylesheet" />
<!-- Add jQuery library -->
<script type="text/javascript" src="js/libs/jquery-1.6.2.min.js"></script>
<!-- Add Facebook Friend Selector JS -->
<script type="text/javascript" src="friend-selector/jquery.friend.selector-1.2.1.js"></script>
<!-- Friend Selector Integration -->
<script type="text/javascript">
jQuery(document).ready(function($) {
var id = 0;
$(".bt-fs-dialog").fSelector({
max: 1,
onSubmit: function(response){
id = response[0];
alert(id);
FB.ui({
method: 'feed',
link: 'https://developers.facebook.com/docs/dialogs/',
caption: 'My text',
to: id,
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
}
});
});
</script>
</head>
<body>
<!-- Facebook Integration -->
<script src="http://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '1399631740271365', // Facebook Application ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.authResponse) {
$(".connect").attr("class", "logout").text("Logout");
$(".fs-dialog-container").show();
$(".logout").click(function(){
FB.logout(function(response) {
location.reload();
});
});
} else {
}
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
jQuery(document).ready(function($){
$(".connect").click(function(){
FB.login(function(response) {
if (response.authResponse) {
location.reload();
} else {
// User cancelled login or did not fully authorize
}
}, {scope: 'user_groups'});
});
});
</script>
Connect
<br />
Click here
</body>
</html>
I can select the friend, the dialog box shows ok, and finally my alert showing: "'Post was published.'" also displays, but still if i enter to my friend's wall, i can't see my post.
I have also tried posting to my own wall, and it's the same.
Any ideas?
Thanks

Facebook Share Button Functionality

I want to add Facebook share button in my website so that user can share any post ,content of given url.
I want to know how can I get that either user is shared something or not on Facebook because I have to store user data in database if user share any post,content of given url from my website.
<a href="https://www.facebook.com/sharer/sharer.php?u=example.org" target="_blank">
Share on Facebook
</a>
I have found a solution .
code :-
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<title>My Feed Dialog Page</title>
<script src="http://code.jquery.com/jquery-latest.pack.js" type="text/javascript"></script>
</head>
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<a onclick='postToFeed(); return false;' style="cursor:pointer;"><img src="img/xyz.jpg"></a>
<p id='msg' style="display:none"><?php echo $_REQUEST['id'] ?></p>
<script>
FB.init({appId: "your app id", status: true, cookie: true});
function postToFeed() {
var obj = {
method: 'feed',
//redirect_uri: 'YOUR URL HERE',
link: 'https://www.abc.in/',
picture: 'http://fbrell.com/f8.jpg',
name: 'abc',
caption: 'User Has Won points ',
description: 'Share Test.'
};
function callback(response) {
//document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
var id=$("p").html();
if(response['post_id']!=null)
{
$.ajax({
url:'customer.php',
data:'fbpoints='+'1'+'&customer_id='+id,
dataType:'html',
success:function(res){ alert(res);
}
});
}
}
FB.ui(obj, callback);
}
</script>
</body>
</html>

Facebook JS sdk Error in retrieving email in login response

i ma using Facebook JavaScript SDK for my FB iframe app. i wnat to get teh user email id in login state
here is my code......
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mettter</title>
</head>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script>
FB.init({appId:'1*********', xfbml: true, cookie: true, oauth: true, fbconnect: false}); FB.getLoginStatus(function(response) {
if (response.authResponse) {
// logged in and connected user, someone you know
FB.api('/me', function(resp) {
alert('Your name is... ' + resp.name);
alert('Your email is.... ' + resp.email);
});
} else {
// no user session available, someone you dont know
alert("i dont know ");
FB.api('/me', function(res) {
alert('Your name is ' + res.name);
alert('Your email is ' + res.email);
});
}
});
</script>
<body>
<h1>Welcome</h1>
</body>
</html>
now when i hit my app URL.. i see a log in to app window i click log in then i see allow window asking for publish streams and when i click allow the the else alert is fired and conatains undefined instead of name and email and the URL contains this message
http://apps.facebook.com/palmchipprojecta/?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.#_=_
i am not getting whats wrong in it??

Facebook Login : How do I get the users email?

I'm new to the facebook api, but I have this:
<html>
<head>
<title>My Facebook Login Page</title>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'my_app_id', cookie:true,
status:true, xfbml:true
});
</script>
<fb:login-button perms="email">Login</fb:login-button>
</body>
I would like to know, when a user accepts my perms or when they return to my site, how do I get that users email adderss?
this will help :
FB.api('/me', function(user) {
if(user != null){
document.write(user.email);
}
})
call this function after user gives you permission
Check out the javascript sdk documentation, they have a similar example of doing this. Try something like:
FB.api(
{
method: 'fql.query',
query: 'SELECT email FROM user WHERE uid='+FB.getSession().uid
},
function(response) {
alert('Email is ' +response[0].email);
}
);

Create A Facebook Status Update Box for Website

I want to know how I can update my Facebook status (and allow other users to update theirs) from a website.
I found this http://developers.facebook.com/docs/reference/rest/status.set/ but couldn't figure out how to get the information from a form to the URL.
Form: USERS STATUS
https://api.facebook.com/method/status.set?status=USERS+STATUS&access_token=********************&format=json
Could anyone shed some light on this, or help me? :(
Update!
I found this piece of coding
<html>
<head>
<title>My Great Website</title>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'128083010546416', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'feed',
message: 'Facebook for Websites is super-cool'});
</script>
</body>
</html>
So, how do I get the text from a form (or something) to the "message" box?
No, you can't fill the box in the Facebook Dialogs with the data you have. Instead you should use FB.api:
var body = 'Reading Connect JS documentation'; // Content to share
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occurred');
} else {
alert('Post ID: ' + response.id);
}
});