Facebook JavaScript API: Get Facebookfriends name and pictures

Add this coe to body element of your html file.....

<div id="findAllFriends">
    <div id="fb-root"></div>    
    <div class="fb_login_user_status">
        <a class="fb_button fb_button_medium">
            <span id="fb-auth" class="fb_button_text">Log In with Facebook</span>
     <div class="fbUser" id="user-info"></div
    <div id="friendslistFB" >
       <table id="fbFriends" width="100%" border="0" >

/**** Java Script code ********/

var facebookAppId='your facebook app id';
window.fbAsyncInit = function() {
  FB.init({ appId: facebookAppId, 
   status: true, 
   cookie: true,
   xfbml: true,
   oauth: true});
  function updateButton(response) {
    var button = document.getElementById('fb-auth');
    if (response.authResponse) {
       //user is already logged in and connected
       var userInfo = document.getElementById('user-info');
       FB.api('/me',{fields: 'name,id'}, function(response) {
           userInfo.innerHTML = response.name+" is connected";
           button.innerHTML = 'Logout';
       button.onclick = function() {
           FB.logout(function(response) {
                var userInfo = document.getElementById('user-info');
    }else {
        //user is not connected to your app or logged out
        button.innerHTML = 'Log In with Facebook';
        button.onclick = function() {
           FB.login(function(response) {
         if(response.authResponse) {
                  FB.api('/me', function(response) {
                      var userInfo = document.getElementById('user-info');
                 userInfo.innerHTML = response.name+" is connected";
              }else {
                //user cancelled login or did not grant authorization
  } // end of updateButton()

  // run once with current status and whenever the status changes
  FB.Event.subscribe('auth.statusChange', updateButton);

(function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol 
     + '//connect.facebook.net/en_US/all.js';

var facebookFriendsIds=new Array();
var facebookFriendsName;

function getFriends() {
var htmlcontent;

    FB.api('/me/friends', function(response) {
        if(response.data) {
        facebookFriendsIds=new Array();
        facebookFriendsName=new Array();
        var headerTable='<tr><td style="font-size: 14px;color:red">Facebook friends</td><td></td><td></td></tr>';
            $.each(response.data,function(index,friend) {
                 htmlcontent='<tr id=fb_'+friend.id+'><td><img height="30px" width="30px" src="https://graph.facebook.com/' + friend.id 
                 + '/picture" /></td>'
                 +'<td class="fb_friendsName">'+friend.name+'</td>'
                 +'<td><input type="checkbox" name="checkboxFB" id="checkboxFB" /></td></tr>';

        } else {

Popular posts from this blog

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Session timeout interceptor in struts 2