Facebook Connect API key error (javascript sdk)

I am trying to implement Facebook Connect on a website. I am trying to work with the Javascript SDK from Facebok. I am new to this and, unfortunately, most of the links provided on WIKI Facebook are out of date ... Return 404 not found. In any case, I added this code to the end </body> :

 <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> <div id="fb-root"></div> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"> </script> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> FB.init({ appId : '12344', // my real app id is here status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : false // parse XFBML }); FB.login(function(response) { if (response.session) { if (response.perms) { alert('user is logged in and granted some permissions'); // user is logged in and granted some permissions. // perms is a comma separated list of granted permissions } else { alert('user is logged in, but did not grant any permissions'); // user is logged in, but did not grant any permissions } } else { alert('user is not logged in'); // user is not logged in } }, {perms:'email'}); </script> 

And I have a button to enter another place (much before the above scripts) on the same page with which:

 <fb:login-button v="2">Connect with Facebook</fb:login-button> 

This button is displayed as a regular fb connect button, and clicking on it opens a new popup window, as usual. The problem is that it shows the error "invalid api key specified". When checking the address bar of the pop-up window, I see that api_key = undefined is passed to it: (

Any ideas on this? I have been trying to fix this in the last 5 hours ... Please help me find out why the correct API key is not being sent to the popup.

Thanks in advance.

+7
javascript login facebook sdk connect
source share
3 answers

I am doing the same thing and I found an example that is very simple to implement and understand (use jQuery here, but you can do the same without libraries):

 <body> <div> <button id="login">Login</button> <button id="disconnect">Disconnect</button> </div> <div id="user-info" style="display: none;"></div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> // initialize the library with the API key FB.init({ appId : '12344' }); // fetch the status on load FB.getLoginStatus(handleSessionResponse); $('#login').bind('click', function() { FB.login(handleSessionResponse); }); $('#disconnect').bind('click', function() { FB.api({ method: 'Auth.revokeAuthorization' }, function(response) { clearDisplay(); }); }); // no user, clear display function clearDisplay() { $('#user-info').hide('fast'); } // handle a session response from any of the auth related calls function handleSessionResponse(response) { // if we dont have a session, just hide the user info if (!response.session) { clearDisplay(); return; } // if we have a session, query for the user profile picture and name FB.api( { method: 'fql.query', query: 'SELECT name, pic FROM profile WHERE id=' + FB.getSession().uid }, function(response) { var user = response[0]; $('#user-info').html('<img src="' + user.pic + '">' + user.name).show('fast'); } ); } </script> </body> 

Look here for all the code and here you can find another resource.

+4
source share

I set my address for connecting facebook to www, and I accessed my test site using non www, when I switched to the www version of fb connect, it worked fine.

+3
source share

You need to set the post-authorize canvas url and make sure the base url of the canvas is the prefix of the url after authorization.

+1
source share

All Articles