Showing posts with label Facebook. Show all posts
Showing posts with label Facebook. Show all posts

Tuesday, October 2, 2012

Fetchinng Facebook Friend List Running Example Using Javascript Sdk

Only replace your Api Id from YourApiIdHere and fetch friend information acording to requirement


<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
        <title> 'FbFriends'</title>
        <script src="http://connect.facebook.net/en_US/all.js"></script>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <!--<link rel="stylesheet" type="text/css" href="styles.css">-->
  </head>
    <body>
     <div id="fb-root"></div>
   <script src="http://connect.facebook.net/en_US/all.js#appId=229823833732087&amp;xfbml=1"></script>
<fb:login-button autologoutlink="true" scope="email,publish_stream,offline_access,friends_birthday,friends_location,friends_photos,friends_about_me,read_friendlists,read_friendlists,friends_hometown,user_location,user_hometown,user_website,user_birthday,user_groups,friends_groups,user_online_presence" size="large"></fb:login-button>
 <script>
 
        FB.init({
       
        appId  : 'YourApiIdHere like 35803822233227 ',
         status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true  // parse XFBML
       
        });
       
        FB.getLoginStatus(function(response) {
        if (response.authResponse) {
        //getting current logged in user's id from session object
        var globaluserid=response.authResponse.userID;
       
        //fetching friends uids from 'friend' table. We are using FB.api syntax
       
        FB.api(
       
        {
        method: 'fql.query',
        query: 'SELECT uid2 FROM friend WHERE uid1='+globaluserid
        },
       
        function(response) {
        //once we get the response of above select query we are going to parse them
        for(i=0;i<response.length;i++)
        {
        //fetching name and square profile photo of each friends
        FB.api(
        {
        method: 'fql.query',
        query: 'SELECT name,pic_square FROM user WHERE uid='+response[i].uid2
        },
        function(response) {
        //creating img tag with src from response and title as friend's name
        htmlcontent='<img src='+response[0].pic_square+' title='+response[0].name+' />';
         //appending to div based on id. for this line we included jquery
         $("#friendslist").append(htmlcontent);
         }
       
        );
       
        }
       
        }
       
        );
       
        }
       
        });
       
        </script>
       <div id="fb-root"></div>
        <table width="100%" border="0">
          <tr>
             <td align="left">
                 <div id="friendslist"> hifriend </div>
             </td>
          </tr>
        </table>
  </body>
</html>
 

Add a comment

Post on Friend's Wall without Facebook Pop up using Javascript Sdk.

function PostOnFriendsWall()
{
        var access_token=document.getElementById("access_token").value;
        var sendername=document.getElementById("sendername").value;
        status1 = document.getElementById('message').value;
        var facebookid = document.getElementsByName("facebookid");
             
        FB.api(
        {
            method: 'stream.publish',
            message: status1,
            target_id: facebookid,
            access_token:access_token,
            attachment: {
            name: ''Your Message Here by'+sendername+' via Javascript Sdk.',
            caption: 'Your Caption Here',
            description: ('Your Discription Here'),
            href: 'Your URL Here where you want to redirect after click',
            media: [
                    {
                        type: 'image',
                        href: 'Your URL Here where you want to redirect after click',
                        src: 'Your Website Image Url if you want to display your logo on Friend's Wall otherwise it'
                    }
                    ]
        },
            action_links:    
            [
                { text: 'Givora', href: 'Your URL Here where you want to redirect after click' }
              ]
        },
          function(response) {
            if (response == 0){
                alert("Error");
            }
            else
            {
                 alert("Wall Posted successfully");
            }
          }
        );
    } 

Wall Post on Your Facebook Wall using Javascript Sdk

unction postOnSenderWallForMoneyGift()
{
    var FriendsName = document.getElementsByName("FriendsName");
    var access_token=document.getElementById("access_token").value;          
    for (i = 0; i< FriendsName.length; i++)
    { 
        recipient = FriendsName[i].value;
        FB.api(
        {
            method: 'stream.publish',
            access_token:access_token,
            attachment: {
            name: ''Your Message Here by'+sendername+' via Javascript Sdk.',
            caption: 'Your Caption Here',
            description: ('Your Discription Here'),
            href: 'Your URL Here where you want to redirect after click',
            media: [
                    {
                        type: 'image',
                        href: 'Your URL Here where you want to redirect after click',
                        src: 'Your Website Image Url if you want to display your logo on Friend's Wall otherwise comment this'
                    }
                    ]
            },
            action_links:    
            [
                { text: 'Your Website Name', href: 'Your URL Here where you want to redirect after click' }
              ]
          },
          function(response)
          {
            if (response == 0)
            {
                alert('Your facebook status not updated. Give Status Update Permission.');
            }
            else
            {
                alert('Your facebook status updated');
            }
          }
        );
  } // End of for loop For Facebook Ids (Till No Of Friends Length)   
}

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...