Facebook FQL url likes of friends work strange

北慕城南 提交于 2020-01-06 15:18:12

问题


Hi I would like to count the url likes of my friends based on a given url, I have the following piece of code:

    function mQ(url){

        FB.api({
            access_token:'CAACEdEose0cBABMG67fV8Yn5cHo5fkb6kT6npRWO7YQL8zagoFLrz5OFLFIEPVUJhMwf9rql9oAqktDUJMKBGr5NNRXJ73jf418gspbfklvdJs6Kx1EkCRutYhSnSW4Binb4F9AlOUIHfXZC052SOdlgtxTSng6gM4CAZAstpLAoOd1p5pnCpNadnlluMqOxjHo1jx1QZDZD', 
            method: 'fql.multiquery', 
            queries: {
                "query1":"SELECT total_count, like_count, click_count, normalized_url FROM link_stat WHERE url='"+url+"'",
                "query2":"SELECT url FROM url_like WHERE user_id IN (SELECT uid1 FROM friend WHERE uid2 = me())"
            } 
        }, function(response) {
            console.log(response)
            var urlLikes = 0;
            var total = response[0].fql_result_set[0].total_count;
            var likes = response[0].fql_result_set[0].like_count;
            var clicks = response[0].fql_result_set[0].click_count;
            var normalized_url = response[0].fql_result_set[0].normalized_url;
            var results = response[1].fql_result_set
            console.log('Total: ' +total+ ', Likes: ' + likes+ ', Clicks: ' +clicks)
            console.log('Urls: ' + results.length)
            console.log('=========================================================================')
            console.log('Checking for url: ' + url);
            console.log('=========================================================================')

            for(var i = 0; i < results.length; i++){

                var newUrl = decodeURI(url).toLowerCase();
                var newFriendUrl = decodeURI(results[i].url).toLowerCase();

                if (newUrl == newFriendUrl) {
                    urlLikes += 1;
                }

            }

            console.log('Url likes: ' + urlLikes);
        });
    }

I get one link from the second query which is a url and I give it to a friend of mine to like it after he does the counter doesnt increase but instead the url gets removed from the second query list!

What am'I doing wrong here?


回答1:


There are multiple issues with what you trying to implement:

  1. There are lot of questions about how to get user ids of likes in a certain circumstances. The short answer is - if you spent too much time and have not found a solution - you can't get those likes easily, or can't get them at all. So, facebook won't let you have the user ids that liked a specific urls, and you won't find a simple solution or guided documentation from facebook regards it. similar issue reference

  2. Lets think numbers. If you have 100 friends, and all of them liked at least 100 urls during their facebook life. It means that your "query2" query should result set of 10,000 urls, and this is not practical for fql query. There are a lot of posts about it on stackoverflow and even on facebook blog posts. You must limit such queries to a certain number that you have tested. Sometimes it might be thousands, and sometimes not more than few hundreds. In your case, i would use hundreds. So, one way accomplish your task is to limit query2 with "LIMIT 0,100" - try it and you'll see that the multyquery work. The next thing to do will be to "paginate" over the rest of the results by looping the offset parameter. So, you'll have to make 100 fql requests in order to get all the urls that your friends liked. Thus:

  3. What you trying to do is not possible to accomplish in real time (one query).

If your access token has the user_likes and friends_likes permissions that is all you need to query the url_like table.



来源:https://stackoverflow.com/questions/21459792/facebook-fql-url-likes-of-friends-work-strange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!