Question

Je suis assez nouveau à Facebook et je suis en train d'afficher une boîte de dialogue simple qui va écrire sur le mur ... Mais pas de chance ... :-(

J'ai essayé ceci:

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

Mais il se connecte toujours « Non connecté », même si je suis connecté sur Facebook, et la boîte de dialogue me donne cette erreur:

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

Je l'ai cherché partout, mais je ne peux pas voir comment obtenir le partout de access token.

Qu'est-ce que je fais mal?

Merci d'avance ...

Était-ce utile?

La 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.

Autres conseils

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!!!
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top