0

Hello I'm trying to implement a url like counter but I want it to take into account only likes from my friends. Long story short how many of my friends liked the url "http://www.domain.com/something"

I've been trying this 2 days now with no success, here are some queries I'm experimenting with so far

"query1":"SELECT user_id FROM like WHERE object_id IN (SELECT id FROM object_url WHERE url = '" + url + "') LIMIT 5000"
"query2":"SELECT url FROM url_like WHERE user_id IN (SELECT uid1 FROM friend WHERE uid2 = me()) AND strpos(url, '"+url+"') = 0"
"query3":"SELECT total_count, like_count, click_count FROM link_stat WHERE url='"+url+"'",
"query4":"SELECT url FROM url_like WHERE user_id IN (SELECT uid1 FROM friend WHERE uid2 = me())"

Some of them work together in a fql.multyquery Anyway I keep testing with friend accounts and the results are wrong, nothing works and I feel really disappointed.

I would really appreciate a working example or some guidance.

PS:(app has full access to everything.)

0x_Anakin
  • 3,229
  • 5
  • 47
  • 86
  • i posted an answer on [your similar question](http://stackoverflow.com/questions/21459792/facebook-fql-url-likes-of-friends-work-strange/21647892#21647892) that might help you out – arty Feb 08 '14 at 16:36

1 Answers1

0
SELECT url FROM url_like WHERE user_id IN (SELECT uid1 FROM friend WHERE uid2 = me()) AND url = "<yourURL>"

should work but it doesn't.

Facebook times out if request takes more than 5 seconds. For getting the data you are asking for FB needs to search each URL liked by each of your friends. In addition complexity depends on the amount of friends. But definitely it is a complex search. Furthermore FQL lacks some SQL syntax getting complex queries close to impossible. My suggestion is to query all your friends links likes and iterate over them.

Sample in pseudo-code:

X = 50
count = 0
friendNumber = queryFriendNumber();
for (Y=0;Y<friendNumber; Y+=X )
    data += SELECT url FROM url_like WHERE user_id IN (SELECT uid1 FROM friend WHERE uid2 = me() LIMIT X OFFSET Y)
data.forEach(url)
    if url == "http://miurl.com" then
        count++
print(count)

Remember you need the friends_likes permission for reading friend's likes.

Mardie
  • 1,663
  • 17
  • 27