Getting all likes from a specific user on a news wall with fewer graph API calls Right now, my solution counting likes of a specific user is 


Starting a recursive call on the "/{user-id}/posts" edge
Iterate through all posts
On each post iterate through each like on the likes edge


If someone knows a better, easier way with less graph API calls necessary, please let me know!

/*
*
*   Count my_user_id likes in wall of user "123"
*
*   ex: url = /123/posts
*   
*   setTimeout to avoid exceed api level rate limit, code 613
*/

function findMyLikes(url,my_user_id,count,callback) {
    console.log(url);
    FB.api(url, function (response) {
        if (response.data) {
            response.data.forEach(function (post) {
                //console.log(post);
                if (post.likes) {
                    post.likes.data.forEach(function (like) {
                        if (like.id == my_user_id) {
                            count++;
                        }
                    });
                }
            });
        }

        if (response.paging &amp;&amp; response.paging.next) {
            setTimeout(function() {findMyLikes(response.paging.next,my_user_id,count,callback)},1000);
        } else {
            callback(count);
        }
    });

};
Interesting / fun question.

I don't think there is much to improve there to reduce the API call count.

From a once over, these are some things you might want to look at:


forEach is still slower than the good old for loop, not sure that matters for you.
Don't use console.log in production code
Don't keep commented out code in production code
Does it make sense to keep comparing to my_user_id if you already found a match ? It is not like you could like the same post twice ? (One more (better) argument to not use forEach here)
my_user_id -> myUserId -> id , always apply lowerCamelCase plus keep it simple


Not relevant after comment


You say you are using the likes edge in your comment, so you might want to mention that in your example ex: url = /123/posts/likes ?
If post.likes is not set while using the likes edge, then something serious is going on , consider an early 'return callback(count);`
Same thing for if (response.data)