Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API: FB.login() called before calling FB.init()

Tags:

I'm trying to use the new Facebook Graph API on my website. This is what I have:

Somewhere on the page:

<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button> 

Right after the tag:

<div id="fb-root">     </div>     <script type="text/javascript">         window.fbAsyncInit = function () {             FB.init({ appId: '<%= ConfigurationManager.AppSettings["FBAppId"] %>', status: true, cookie: true, xfbml: true });              /* All the events registered */             FB.Event.subscribe('auth.login', function (response) {                 // do something with response                 alert("login success");             });             FB.Event.subscribe('auth.logout', function (response) {                 // do something with response                 alert("logout success");             });              FB.getLoginStatus(function (response) {                 if (response.session) {                     // logged in and connected user, someone you know                     alert("login success");                 }             });         };         (function () {             var e = document.createElement('script');             e.type = 'text/javascript';             e.src = document.location.protocol +             '//connect.facebook.net/en_US/all.js';             e.async = true;             document.getElementById('fb-root').appendChild(e);         } ());     </script> 

but when I click on the generated login button, nothing happens.

In addition, I'm getting

FB.getLoginStatus() called before calling FB.init(). 

in Firebug console.

Any ideas?

like image 999
sabbour Avatar asked May 18 '10 09:05

sabbour


People also ask

How to initialize Facebook SDK?

The method FB. init() is used to initialize and setup the SDK. If you have followed our SDK quickstart guide, you won't need to re-use this method, but you may want to customize the parameters used. All other SDK methods must be called after this one, because they won't exist until you do.

How to integrate Facebook Login in website?

#3: Set Up Facebook Login for Your Website At this point, you'll see Facebook Login among your website app options. Click the Set Up button to get started. Next, you'll fill in the information about how and where you'll use the app. You can add the Facebook Login feature on any app across multiple devices.

Where is client OAuth Settings in Facebook?

In your Facebook app configuration, click on the Settings tab on the left-hand navigation menu. Then go to the Advanced tab at the top and scroll down to the Client OAuth Settings section.


2 Answers

I can't believe it, I was referencing a non existing key in the Web.config hence FB.init was failing silently.

It works as expected now.

To be clearer I wasn't passing the appId to FB.init, once I did, it worked.

like image 60
sabbour Avatar answered Sep 21 '22 05:09

sabbour


Had the same issue, here is the solution that worked for me. Just put the following in your head section or in other words, add the app_id to the source of the facebook js.

<script src="//connect.facebook.net/en_US/all.js&appId=xxxxxxxxxxxxxxx" type="text/javascript"></script>

like image 45
Robot Boy Avatar answered Sep 19 '22 05:09

Robot Boy