Question

I'm fairly new to Facebook and I'm trying to display a simple dialog that will write to the wall... But with no luck... :-(

I tried this:

<!DOCTYPE HTML>
<html xmlns:fb="https://www.facebook.com/2008/fbml">
    <body>
        <script src="http://connect.facebook.net/da_DK/all.js"></script>
        <div id="fb-root"></div>
        <script>
            FB.init({appId: '172225549532081', xfbml: true, cookie: true});

            FB.getLoginStatus(function(response) {

                  if (response.authResponse && response.status=="connected") {
                    console.log("loged in");
                  } else {
                    console.log("not logged in");
                  }
            });
            FB.ui({
                display: 'iframe',
                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.'

            });
        </script>
    </body>
</html>

But it always logs "Not logged in", even if I'm logged into Facebook, and the dialog gives me this error:

API Error Code: 102
API Error Description: Session key invalid or no longer valid
Error Message: Iframe dialogs must be called with a session key

I've searched all over, but I can't see how to get the access token anywhere.

What am I doing wrong?

Thank you in advance...

Was it helpful?

Solution

Try this:

 FB.login(function(response) {
   if (response.authResponse) {
     console.log('Logged in');
   } else {
     console.log('Not logged in');
   }
 });

Just because the user is logged in on facebook.com, they are not automatically logged into your site. They have to authenticate on your domain, with your app first. You will need to call the login function after they have clicked something, as it will cause a pop up.

OTHER TIPS

Is your user connected to your app?
If the user is not connected to your app, then you can ask the user to login to your app by having a login button(http://developers.facebook.com/docs/reference/plugins/login/)

The code below will check the user's status and show a login button if needed.
Don't forget to set perms attribute to have appropriate permission, such as

FB.getLoginStatus(function(response) {
  if (response.authResponse) {
    // logged in and connected user, someone you know
  } else {
    // no user session available, someone you dont know
    $('<fb:login-button></fb:login-button>').appendTo('body')
  }
});
FB.ui({
    display: 'iframe',
    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.',
    access_token: FB.getAuthResponse().accessToken     // **This should work and tested** also!!!
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top