Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access a user's friend status using Facebook Graph API?

I am making an web app that shows the authenticated user's friends statuses. Is there anyway I can do this using Facebook's graph API? The only thing I am finding is FQL which I can't use because I am not allowed to use php.

Edit: Also I don't need alot of statuses. I only need their friends latest one.

Edit: fbID is the facebook ID. Here is my code:

<script>
var self;
  (function(d){                                                                             // Load the SDK Asynchronously
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

  window.fbAsyncInit = function() {                                             // Init the SDK upon load
    FB.init({
      appId      : '190843834372497', // App ID
      channelUrl : 'http://people.rit.edu/~cds7226/536/project3/channel.html', // Path to your Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // listen for and handle auth.statusChange events
    FB.Event.subscribe('auth.statusChange', function(response) {
      if (response.authResponse) {                                              // user has auth'd your app and is logged into Facebook
        FB.api('/me', function(me){
          if (me.name) {
            document.getElementById('auth-displayname').innerHTML = me.name;
            //Add rest of code here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            self=me;
          }
        })
        document.getElementById('auth-loggedout').style.display = 'none';
        document.getElementById('auth-loggedin').style.display = 'block';
      } else {                                                                  // user has not auth'd your app, or is not logged into Facebook
        document.getElementById('auth-loggedout').style.display = 'block';
        document.getElementById('auth-loggedin').style.display = 'none';
      }
    });

    document.getElementById('auth-loginlink').addEventListener('click', function(){ // respond to clicks on the login and logout links
      FB.login(function(response){},{scope: 'friends_status,read_stream'});
    });
  } 
</script>

Then this function executes when you click the button. It gets the User's last checked in location, and personal information including their facebook ID.

function getFriendsCheckin(token)
{
    $.getJSON('https://api.foursquare.com/v2/checkins/recent?oauth_token='+token+'&v='+"20120514",function(results){
    //console.log(results);

    $.each(results['response']['recent'], function(key,value){
        //console.log(key+' : '+value);
        //Friends personal info
        var fullName = value['user']['firstName']+" "+value['user']['lastName'];
        var timeStamp = value['createdAt'];
        var photo = value['user']['photo'];
        var fbID = value['user']['contact']['facebook'];
        //Where they last checked in
        var locName = value['venue']['name'];
        var location = new google.maps.LatLng(value['venue']['location']['lat'],value['venue']['location']['lng']);
        //setMarker(location,fullName+'@'+locName);
        setCustomMarker(location,fullName+'@'+locName,fbID,photo);
    });
})

}

Lastly this is where the problem is. This function is suppose to show the user's friendd last status when the maker is clicked on google maps.

function setCustomMarker(location,title,fbID,icon)
{
//alert("here");
var marker = new google.maps.Marker({
    position: location,
    draggable: false,
    map: map,
    title: title,
    //icon: icon
    //icon: new google.maps.MarkerImage({url: icon, size: new google.maps.Size({width:10,height:10})})
});

google.maps.event.addListener(marker,'click',function(){
console.log('SELECT status_id,message FROM status WHERE uid='+fbID);
    FB.api(
        {
            method: 'fql.query',
            query: 'SELECT status_id,message FROM status WHERE uid='+fbID
        },
        function(response){
            console.log(response);
        }
    );//*/
});

}

like image 619
Christopher Stephenson Avatar asked Feb 02 '26 06:02

Christopher Stephenson


1 Answers

May be you are confused, but you can use fql with javascript sdk.

e.g.

FB.api(
  {
    method: 'fql.query',
    query: 'SELECT name FROM user WHERE uid=me()'
  },
  function(response) {
    alert('Your name is ' + response[0].name);
  }
);

See reference

If you use graph api, this should work (not tested but you can check and updated me)

FB.api('/','POST',{
    access_token:'<your_access_token>',
    batch:[
        {
            "method": "GET",  
            "relative_url": "me/friends?limit=5",
            "name": "get-friends"
        },
        {
            "method": "GET",
            "depends_on":"get-friends",
            "relative_url": "{result=get-friends:$.data.*.id}/statuses"
        }
    ]
},function(response){
     console.log(response);

})

Ofcourse you need permission required for reading status updates of friends.

like image 117
Jashwant Avatar answered Feb 03 '26 21:02

Jashwant