Monday, June 14, 2010

Phase 1: bulding a Facebook app

Facebook has a rich documentation site for building Apps. The only problem I had is that there are different layers of API which actually carry out the same operation, and so it is difficult to understand the one you want to use. First step is to register your future app and to edit it. Then, I used the Social plugin for Login, which is a trivial way for remote login and authentication in Facebook. The code is simply

<!-- login in facebook with extended perms -->
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream" faces="true"></fb:login-button>

This will use FB extensions to HTML, which must be activated before with an asynchronous initialization of Facebook javascript library (noticed the appId:, and xfbml:true down below
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '117083285001944', status: true, cookie: true,
xfbml: true});
};
(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);
}());

This function uses the FB.UI Api call to publish on your facebook account
function streamPublish(name, description, caption, hrefTitle, hrefLink, userPrompt, thumb, urlThumb){
FB.ui(
{
method: 'stream.publish',
message: '',
attachment: {
name: name,
caption: (caption),
description: (description),
href: hrefLink,
media: [{ type: 'image', src: (thumb), href: (urlThumb)}]
},
action_links: [
{ text: hrefTitle, href: hrefLink }
],
user_prompt_message: userPrompt
},
function(response) {

});
}
</script>

No comments:

Post a Comment