facebook - Javascript FB.api - undefined error - Stack Overflow

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

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=".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=".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!

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

Share Improve this question asked Feb 9, 2012 at 20:40 dbfdbf 6,5192 gold badges42 silver badges69 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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.

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./docs/guides/web/#login

To overe 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);
});

  } 
 });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745536476a4631928.html

相关推荐

  • facebook - Javascript FB.api - undefined error - Stack Overflow

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

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信