1

I am trying to use JS interface for facebook api and it is my first application for it. Here is a snippet:

HTML:

    <div id="fb-root"></div>
    <script src="https://connect.facebook.net/ru_RU/all.js"></script>
    <script type="text/javascript">facebook_init();</script>

JS:

function facebook_init() {
    FB.init({
      appId      : '<MY APP ID IS HERE>',
      channelUrl : '/media/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    FB.api('/me', function(response) {
              alert('Your name is ' + response.name);
            });
}

channel.html:

<script src="https://connect.facebook.net/ru_RU/all.js"></script>

I have 'Your name is undefined' when I load this page. But this code

FB.ui({ method: 'apprequests',
      message: 'MSG',
      title: 'TITLE'});

works as expected. Could you please help me? Thanks!

3 Answers 3

2

If you log your response variable via console.log(response) you'll see what's wrong: You'll get an error object with this message:

"An active access token must be used to query information about the current user."

So if you want to get information about the current user you have to send also an Access Token. To get more information about this check the Facebook JS SDK page.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to make sure that the user has logged into Facebook and authorized your app, before you call FB.api('/me', ...).

Here's the general information: http://developers.facebook.com/docs/guides/web/#login

Comments

0

To overcome with Undefined problem use the following code:

  window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
  appId      : '<APP ID>',                        
  status     : true,                                 
  xfbml      : true                                 
});

// Additional initialization code such as adding Event Listeners goes here

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
alert("connected");
connecter=true;
FB.api('/me', function(user) {
alert(user.name);
alert(user.first_name);
alert(user.last_name);
alert(user.email);
});

  } 
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.