Thursday, February 10, 2011

Connect your Facebook friends in your application

The Basics:

Facebook application can be developed using the following methods
1.       XFBML.
2.       Javascript with calls to the Javascript client library.
3.       Code in any language, with calls to the Facebook REST API.

I have implemented the facebook with the help of Facebook REST API for selecting the friends from your login and posting the invitation to the wall, the invitation is a url for getting connected to my achieve street site.
FYI: The XFBML is going to be expired in January and will be out of scope, so you think twice before getting it implemented.

Configuring Connect Application
Integrating/developing an application with Facebook requires an API key and a secret key with whom Facebook will authenticate your application on Facebook platform - this is called oauthentication.
FYI:   OAuth: The simplest definition can be OAuth protocol enables users to provide third-party access to their web resources without sharing their passwords

How to Retrieve the API Key and Secret Key
1.       Navigate to Facebook developer center and request for new application which can be obtained from your facebook login.
  1. Choose an appropriate application name (My application's name is AchieveStreet).
  2. Navigate to basic tab, there you can see API key/ secret key is given.
  3. Provide a small description about your application.
  4. Navigate to connect tab. Provide the applications full.
  5. Navigate to Advanced tab and on Advanced Settings, choose web.
  6. Choose sendbox mode enable/disable. Enable allows only the developers of application to see it.
  7. Save your settings.
The sample application for the facebook connect can be found in

How to make connection with the Facebook and Posting into the wall
API’s needed:
Facebook.Web.dll, Facebook.dll

How to establish the connection with Facebook
Api api = new Api(connectAuthentication.CurrentSession);

Posting to the wall
api.Stream.Publish(strbody, null, null, target user id, source user id);
the userid is the unsigned long int.

For posting into the wall you need to give permission for the login user to write the message into wall below is the code for that to do from the application

function setGrandPermission(isRead, isPublish) {

    try {
        FB_RequireFeatures(["Api"], function () {

            //Allow Permission for accessing the friends
            var api = FB.Facebook.apiClient;

            FB.Connect.requireSession(function () {
                var session = api.get_session();

                api.users_hasAppPermission("read_stream", function (hasRead) {
                    api.users_hasAppPermission("publish_stream", function (hasPublish) {

                        var permissions = [];


                        if (isRead)
                            if (!hasRead) permissions.push("read_stream");

                        if (isPublish)
                            if (!hasPublish) permissions.push("publish_stream");


                        if (permissions.length > 0) {                        
                            FB.Connect.showPermissionDialog(permissions.join(","), function (authorized) {                            
                            });
                        }
                    });
                });
            });
        });
    }
    catch (err) {throw err.Message;}
}


Using JQuery facebook Multi-Friend Selection Plugin using Javascript API, Graph API

I would like to thank Thiru and Kumuraguru for helping me to know this topic.

The Javascript API is used to get connected with the Facebook to do more things on Javascript API, to know more on this visit

The Graph API to retrieve the friends list, to know more about Graph API visit

To know more about the facebook api's feel free to email me.

No comments:

Post a Comment