最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Facebook Javascript SDK FB not defined - Stack Overflow

programmeradmin7浏览0评论

I get error FB not defined when using Facebook Javascript SDK

FB.init({
    appId: '{APP ID}',
    status: true,
    cookie: true,
    xfbml: true
});

Jsfiddle

I get error FB not defined when using Facebook Javascript SDK

FB.init({
    appId: '{APP ID}',
    status: true,
    cookie: true,
    xfbml: true
});

Jsfiddle

Share Improve this question edited Apr 26, 2014 at 7:18 B L Praveen asked Apr 26, 2014 at 5:20 B L PraveenB L Praveen 2,0105 gold badges40 silver badges66 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Two things-

  1. I can't see the JS SDK been loaded.

  2. You have to call your FB functions after the SDK is loaded asynchronously, else it will throw that FB is not defined

So, to fix it-

// This will be triggered automatically after the SDK is loaded successfully
// write your FB fucntions inside this
window.fbAsyncInit = function() {
   FB.init({
     appId: '{app-id}',
     status: true,
     cookie: true,
     xfbml: true
   });

   FB.getLoginStatus(function (response) {
     if (response.status === 'connected') {
        GetData();
     } else {
        Login();
     }
  });
};

// JS SDK - this will be loaded asynchronously
(function(d, s, id){
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook/en_US/all.js";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function Login() {
   ...
   ...
}

function GetData() {
   ...
   ...
}

Reference

Edit:

I saw that you are requesting for the permission email and yet not using it. Use the actual email (not the facebook one) with- response.email

发布评论

评论列表(0)

  1. 暂无评论