ene
ene

Reputation: 75

Count Taggable Friends Facebook API

I've done this little function to count how many taggable friends I have when someone log into my app.

function testAPI() {
FB.api('/me/taggable_friends', function(response) {
  var friendsICT = response.data;
  var HowManyFriends = 0;
  for (i=0;i<5000;i++) {
    if (friendsICT[i] != undefined) {
        HowManyFriends++;
    } else {
        console.log(HowManyFriends);
        break;
    };
  };
});
}

I was just wondering if there's some way to do this in a shorted code. I've tried response.data.length but it gives me back an error. Maybe it's just because of the API 2.0!

Upvotes: 0

Views: 1462

Answers (3)

WizKid
WizKid

Reputation: 4908

Just call /me/friends. It will contain a summary with total_count. You can read more about it at https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friends

Upvotes: 1

ene
ene

Reputation: 75

I've found out how to count (and display) them.

function testAPI() {
    FB.api('/me/taggable_friends?limit=5000', function(response) {
    var friendsICT = response.data;
    var HMF = friendsICT.length;
    alert(HMF);
 });
}

I've to add this pieace of code

?limit=5000

to reach all the 5000 friends. Now when I alert it, the lenght is correct! I've found out this ?limit thing searching in the notSoClear Facebook documentation.

Hope this is/will be helpfull for someone! :)

Upvotes: 1

dimxasnewfrozen
dimxasnewfrozen

Reputation: 137

What does the "friendsICT" object look like?

Can't you just do:

var HowManyFriends = friendsICT.length;

Upvotes: 0

Related Questions