views:

957

answers:

2

So maybe the documentation is out of date, or I am just off here. But I have done a slew of FB iframe apps (connect), but I am starting my first FB Connect site. Running it from localhost, and the Connect URL is http:// my_external_IP_address. When I click on the FB login button on my site, it pops up, says waiting for facebook, and it returns my site in that box, with the URL up top with the http:// mysite/?session={session key, user_id, etc.} The user_id is infact my FB id. And so it thinks I am logged in. If I close the popup, I'm not logged in. I'm not sure why the pop up isn't doing the normal fb connect dialog. I'm following these steps.

(I added spaces to the http:// as to not be detected as 'spam')

  1. html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"
  2. right after <body> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript">
  3. At the end, before the body close tag: script type="text/javascript"> FB.init("fbkey", "http://127.0.0.1/xd_receiver.htm"); I have tried using xd_receiver.htm, /xd_receiver.htm (and other combos), and that brings up a blank page. using the http://127.0.0.1 at least does something.

In my config file, which is called before all of those, it checks for a PHP session key to see if they are logged in, if that doesn't exist it looks for a cookie, and if that doesn't exist it does this:

 require_once('includes/facebook.php');
  $facebook = new Facebook($fbkey, $fbsec); 
  $user_id = $facebook->get_loggedin_user();

  if($user_id > 0){
    $user = $ac->getUserFromFB($user_id);
    $_SESSION['user_id'] = $user['user_id'];
  }

The user_id is always empty when I echo it out to the screen to test. The session event never occurs as well. So I don't know what it is doing in the popup, but I think Facebook thinks it is logging me in. Not sure. Pretty stumped on this one. Any help would be appreciated. Thanks!

A: 

I don't know for sure but I suspect the problem is due to you running on your local machine.

My guess is that the Facebook server won't be able to find your machine on 127.0.0.1 as that is a local ip address. You could try using somewhere like whatisyourip.com to get your actual remote ip and use that instead but even then you would need to make sure that you have the necessary port forwarding set up for the FB server to be able to get to your local machine.

All in all, for this kind of site I think it would be easier to develop on an external server rather than a local environment.

Incidentally, I don't have to enter the second parameter for FB.init() - I just use

FB.init(fbkey);

If you haven't already, you could try taking that out completely to see if it helps.

Also I think that the script tag to include the facebook FeatureLoader.js should be before your </head> tag not after the <body> tag

Addsy
I tried removing the xd_receiver text from FB.init(), changed 127.0.0.1 to my external IP (although, this is just a reference for the FB.init JS function, so I think local is fine), and I removed the featureloader to the head tag. And tried a combo of the three with no success. Still pulls up my website in the popup. Thanks for the help though.
Brett
A: 

I've personally found the easiest way to deal with facebook connect is to use winscp to sync my localhost to a server with a domain somewhere. Since fb connect is attached to an application, that application needs to be bound to a domain, which is where the api key gets generated. Somewhere in there, your localhost isnt working, unsurprisingly.

devians