Facebook JS sdk Error in retrieving email in login response - facebook

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??

Related

How to create FB login button

How do we create a link to initiate the FB connect process WITHOUT using one of their built in button forms <fb:login-button ></fb:login-button>
Just add an onclick event to any of your custom buttons and have it call the FB.login event in their javascript sdk.
Full example:
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
Custom Login Button
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: '**yourAppId**', status: true, cookie: true, xfbml : true });
function doLogin() {
FB.login(function(response) {
if (response.session) {
FB.api('/me', function(response) {
alert('Welcome ' + response.name);
alert('Full details: ' + JSON.stringify(response));
}
);
}
} , {perms:''});
}
</script>
</body>
</html>

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);
}
);

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

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>

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);
}
});

Facebook connect login problem

I am trying to have a connect button on my site. Once the user has clicked the facebook login button, the pop up will ask the user to enter the authentication detail and the parent window will either redirect or refresh the page and the login button became a logout button.
My problem is when a user clicked the connect button from the popup, the popup page will redirect to my canvas page rather than closed the popup instead.
Many people have posted this issue, if you have done everything else right, the reason for this is xd_receiver file was not read by the fb.
You need to make sure that where your fb connect button is, you specify the correct path to xd_receiver.html file somewhere on bottom of that page. Something like below:
<script type="text/javascript">
FB.init("your api key here", "xd_receiver.htm");
</script>
It is even better and easier to put the xd_receiver file on your site's root folder and specify it with full domain url like this:
<script type="text/javascript">
FB.init("your api key here", "http://www.yoursite.com/xd_receiver.htm");
</script>
Here's a sample of facebook connect, login and logout, works very well,
Also make sure you add your site url under your app settings -> Website - > Site URL:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Facebook Connect Sample</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/* All the events registered */
FB.Event.subscribe('auth.login', function(response) {
// do something on login
login();
});
FB.Event.subscribe('auth.logout', function(response) {
// do something on logout
logout();
});
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
login();
}
});
};
/* Loading the JS SDK Asynchronously - Refer: https://developers.facebook.com/docs/reference/javascript/ */
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function login(){
window.location = "http://google.com"; // Redirect to Another Page.
/* Show User's Name
FB.api('/me', function(response) {
document.getElementById('login').style.display = "block";
document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";
});
*/
}
function logout(){
document.getElementById('login').style.display = "none";
}
</script>
<p><fb:login-button autologoutlink="true"></fb:login-button></p>
<div id="login" style ="display:none"></div>
</body>
</html>