How to work with Facebook JavaScript SDK? - facebook

Is the Facebook JavaScript SDK something I download and upload to my server? Or is it something I just call from my own JS?
I am looking at their documentation here:
http://developers.facebook.com/docs/reference/javascript/
But got confused half way through :)

The Facebook JavaScript SDK is ran on the client's system (aka the web browser). The SDK is hosted at Facebook and you only need to include it with <script src='http://connect.facebook.net/en_US/all.js'></script>. You don't need to upload it to your server.
You use the SDK from JavaScript client-side.
If it's XFBML that you find confusing: it is translated to HTML and CSS client-side by the JavaScript SDK.

There's no need to upload the JavaScript SDK to your server (unless you want to stick to a particular version). If you want you can just reference the one served by Facebook as you would any other script:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'your app id',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
Or you can load it asyncronously:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'your app id', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>

Related

facebook, google, twitter, linked in login buttons

I'm trying to setup single sign on (SSO) logins for each of these services. I have already setup facebook with a simple piece of code they provide like so:
<fb:login-button>Facebook</fb:login-button>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?php echo $facebook_app_id; ?>', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) { window.location.reload(); });
</script>
This creates a button for you and when you click on it opens up pop up window where you can login and allow the app website access to your facebook account. Is there anything simple like this for google, twitter and linkedin?
For LinkedIn: https://developer.linkedin.com/documents/sign-linkedin

edge.create event not fired in Like box

I am not able to fire the edge.create event in the Like box. However, it works with a normal like button. Is there a restriction?
Here is my coding:
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'ID12456',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
<p>Like Box:</p>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:like-box href="http://www.facebook.com/apps/application.php?id=163685566990893" stream="false"></fb:like-box>
<br/><br/>
<script>
FB.Event.subscribe('edge.create', function(response) {
alert("Ok");
});
</script>
</body>
</html>
Mabe because you're linking your Facebook JavaScript code (all.js) two times.
I tried that code on FB Rell, and it's working.
<h1>Platform like-box Plugin with Defaults</h1>
<fb:like-box name="platform"></fb:like-box>
<script>
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
</script>
Yes this is a known FB bug. See http://developers.facebook.com/bugs/378710432185222/
It seems to work sometimes in some situations and not in others. One solution is to swap in the regular like button instead. If you use the Facebook JS API and an FQL call, you can get access to all the info you need (page name, url, square pic) to recreate a similar looking widget. Not ideal, but it works...

need to invite facebook friends to mysite

I will implement a functionality that let users to invite their facebook friends (explicity choosing or let exclude some of them) to our site (I dont know what is possible with facebook api but possible cases: 1- sending plain email to friends 2- facebook message, invitation in facebook platform). I am facebook platform newbie and dont know where to start. Could you recommend which API should I use (facebook connect , facebook graph etc)? I read that facebook api and permission is changing rapidly. What is the state of the art way of doing this task?
You have to create one facebook app first.
Heres the link for creating facebook app.
https://www.facebook.com/developers/createapp.php
Then after put the following code in your application.
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
//Your app details here
FB.init({appId: 'your-app-id', status: true, cookie: true, xfbml: true});
};
//Load the SDK asynchronously
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<fb:serverfbml>
<script type="text/fbml">
<fb:fbml>
<fb:request-form
action="url-after-inviting"
method="POST"
invite="true"
type="Name of site"
content="Text you want to keep along.
<fb:req-choice url='link-to-your-website'
label='<?php echo htmlspecialchars("Invite Now!",ENT_QUOTES); ?>'/>"
>
<fb:multi-friend-selector
showborder="false"
actiontext="title-text"
exclude_ids="<?php //echo $excludeIds; ?>"
rows="3"
/>
</fb:request-form>
</fb:fbml>
</script>
</fb:serverfbml>

Invite a friend via Facebook is failing all of a sudden

I have the Facebook invite feature on a site that I am working on and all of a sudden it stopped working. Here is what I have:
window.fbAsyncInit = function() {
FB.init({ appId: '145554402127660', status: true, cookie: true, xfbml: true });
};
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<fb:serverFbml width="565px">
<script type="text/fbml">
<fb:fbml>
<fb:request-form method='POST' invite=true
type='Our site'
action='http://somesite.com/step3'
content='this is the place you want to be'>
<fb:multi-friend-selector cols=3
actiontext="Invite your friends to join you our site"
/>
</fb:request-form>
</fb:fbml>
</script>
</fb:serverFbml>
This worked before, but now for some reason I always get this error:
1 XFBML tags failed to render in 30000ms.
Any ideas on what is happening and why this stopped all of a sudden? Also, if there is a new way of doing this, maybe with the Graph API, I would highly appreciate info about it.
got namespace xmlns:fb="http://www.facebook.com/2008/fbml" ?
the answer is here - Facebook FXBML since Yesterday not rendering (IFRAME Canvas)
You'll have to call FB.XFBML.parse after FB.init is complete.
The newest way of doing this is through the Requests 2.0 Dialog, part of the Graph API. It's about 2 months "old". It works through the javascript API.
http://developers.facebook.com/docs/reference/dialogs/requests/
http://developers.facebook.com/blog/post/464

Facebook fanbox widget fbxml problem at Friseur in München

Sometimes iv'e got the problem that no facebook fanbox is load on my companies website Friseursalon München. Can't find a problem in the fbxml code:
<fb:fan profile_id="395375265611" connections="10" width="334" height="285" css="http://www.x-hair.de/cms/css/facebook.css"></fb:fan>
Any suggestions? Anybody else with the same issue?
Thanks,
Stephan
I don't see any mistakes in the facebook fan code.
You should add the facebook xmlns string at the top of your page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml">
This solved some problems for me in Internet Explorer.
You could try to load the newest version of the js SDK.
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});
</script>