Facebook connect ifUserConnected() does not work - FB.Connect is undefined error - facebook

I'm trying to integrate Facebook connect to my website. The login button appears and i'm able to login. The profile picture and the name is displayed properly. However when I try adding the code FB.Connect.ifUserConnected, I get a error message saying FB.Connect is not defined.
This is what I'm doing
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.init({ appId: 'my app id', status: true, cookie: true, xfbml: true });
</script>
<fb:login-button onlogin="fb_login()"></fb:login-button>
<script>
function fb_login() {
$("#SocialConnectButtons").hide();
$("#UserProfile").show();
FB.XFBML.Host.parseDomTree();
}
//ALL UNTIL HERE WORKS AS EXPECTED, BUT THE FOLLOWING LINE FAILS
FB.Connect.ifUserConnected(fb_login);
</script>
Thanks for the help

Here is a good tutorial to get started with new API for facebook connect.

You are using the new Graph API (http://connect.facebook.net/en_US/all.js)
The code you wrote will not work. Check the Graph API javascript SDK here: http://developers.facebook.com/docs/reference/javascript/
and for the API itself:
http://developers.facebook.com/docs/reference/api/

Related

Facebook post integration with my app gives error 191 redirect_uri is not owned by the application

I have an application running on my localhost. I registered this app on facebook with the siteUrl as http://IP:port/app_context
I got the APP Id and when i try to invoke the feed API of facebook , i get the following error :
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
The code to invoke FB is :
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'294615097233384', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'feed',
message: 'Send Message to FB'});
</script>
</body>
Any help will be appreciated. Thanks
Do you have stream post security enabled in the app's advanced settings?
If not, that message should only be appearing if you're authenticating a user and sending them to a redirect_url which doesn't match what you've configured in the app settings

FB.init gives 'root undefined' or 'innerHTML' error

I have written a Facebook website app that gives the possibility to push reactions that people give to news items to there Facebook wall. Everything works fine except in IE8.
When I visit the homepage with IE9 compatibility mode IE8 I get:
Unable to set value of the property 'innerHTML': object is null or undefined
When visit with authentic IE8 I get:
'root' is null or not an object
This is the Facebook code I have on that page:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script>
FB.init({
appId : '${siteConfiguration.facebookAppId}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
I have tried putting the script tags in the and the fb-root in the but I still get the error.
It was right in front of me!
FB quote: The best place to put this code is right before the closing </body> tag.
I placed it in the <head> tag.
Guess you need to reorder your code put the line
afer
so your code now will be
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '${siteConfiguration.facebookAppId}',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>

Facebook login, redirect_uri is not owned by the application. why?

I can't add FB login to my site. I simply registered the application:
URL: http://www.chusmix.com/
DOMAIN: www.chusmix.com
And then I pasted the login code and replaced my APP id in it:
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'212044715486306', cookie:true,
status:true, xfbml:true
});
</script>
<fb:login-button>Login with Facebook</fb:login-button>
</body>
</html>
However when clicking the login button I get Error 191: redirect_uri is not owned by the application
Also this code is in the page: http://www.chusmix.com/game/ according to what Facebook says filling the field DOMAIN makes all pages in the domain able to use Facebook Authorization. However I also tried pointing directly to the domain where the Login Button is and I get the same error.
There isn't even a redirect url.
Update: It seems the Login works in http://www.chusmix.com/game/ but doesn't on http://chusmix.com/game/ (without www).
Is there a way to make it work if the user doesn't type www.? Or do I have to use a redirect?
Try adding the site URL to the app settings Edit Settings->Web Site->Site URL. While you are there you might as well fill in the Site Domain in case you add sub domains in the future.
Use this as you Site Domain: chusmix.com
Make sure every URL in your JS script matches EXACTLY to the Site URL you set up in Facebook, including http://.
Ex:
FB.init({
appId : '128957350986', // App ID
channelUrl : 'zazzlebaytobreakers.com/lib/channel.php', // Channel File
Will cause this error in IE 7 and 8.
Make sure it's:
FB.init({
appId : '128957350986', // App ID
channelUrl : 'http://zazzlebaytobreakers.com/lib/channel.php', // Channel File

Facebook Like notifications?

I saw a website today that stated: "Share/Like this site and get 10% discount". I was wondering: is there any way to track when someone shares/likes my site? Can I store some data of that user in my app?
I know those events have some callbacks, and maybe I can trigger some jQuery magic to send some data vía ajax when the user clicks on the button.
Any ideas?
Thanks!
Similar question was discussed here
FB.Event.subscribe('edge.create', function(href)
{
});
From the above code you can get only href not any User details. So I tired the following code
FB.Event.subscribe('edge.create', function (href) {
FB.login(function (response) {
if (response.session) {
//session object has uid & access token.
}
});
});
The Problem you will have from above code is: Since FB.login will open a pop up window for log in, some browsers will block the pop up or warns the user.
I tried the above code. LIKE functionality works and is posted to user's wall, but regarding getting user info:
Firefox (4.0) - did not warn but it asked the user to authorize APP and access basic information. IE 9 - Gave a warning message about POP UP. Google Chrome : Blocked the log in pop up.
It seems the only way to achieve this is let the user login to website using Facebook Connect first and then get user info using
FB.Event.subscribe('edge.create', function (href) {
// href is the URL of the object that got liked
var x;
FB.getLoginStatus(function (response) {
alert(response);
if (response.session) {
}
});
Check out the Facebook developers site. It contains heaps of information.
http://developers.facebook.com/search?q=Events.create
and
http://developers.facebook.com/blog/post/149/
Something like this should do what you need:
<fb:like href="http://www.google.com"></fb:like>
<!-- Like button to whatever object you want^^ -->
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"
type="text/javascript" charset="utf-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"
type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
FB.init({
appId: 'APP_ID',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('edge.create', function(href)
{
// href is the URL of the object that got liked
// do whatever magic ajax you want
});
</script>

FB.logout not working in IE8

I've integrated facebook login with my application and I want to logout the user from facebook when he logs out of my application. So I did the following:
Logout
This works on Firefox and Chrome but doesn't work on IE8. In IE8 the user is logged out of the application but is not logged out of Facebook.
Anyone else experiencing this?
Please try this one
<script src="http://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script language="javascript" type="text/javascript">
FB.init({
appId: '205734987138498',
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
oauth: true // enable OAuth 2.0
});
function handleSessionResponse(response) {
// FB.XFBML.parse();
}
FB.getLoginStatus(handleSessionResponse);
//////you can optionally put the following in a seprate js file/////////
var Facebook = {}
Facebook.signout = function (url) {
FB.logout();
setTimeout('top.location.href = "' + url + '"', 2000);
}
</script>
<div onclick="Facebook.signout('http://www.uamplify.com');">Call your logout function now, click here</div>
I found the exact same thing and also with the Android browser. Shahid's fix worked for me and then I realized another approach would be to put the redirect within the callback function like this:
function mysignout(url)
{
FB.logout(function()
{
top.location.href = 'url'
});
}
If you're like me, you probably figured FB.logout is just destroying a cookie or something but it appears to make some ajax calls (I guess to revoke authentication on the server) and has different execution times, especially on mobile devices using wireless networks.
2000 ms might not necessarily be enough time for the function to complete, or it could be more than necessary. The callback function executes once FB.logout has completed in every case.