The odd behavior of how my friends' likes are appearing on Facebook FQL URLs

Hey there! I'm trying to keep track of the number of likes on a specific URL shared by my friends. Here's the code snippet I have:

    function countURLLikes(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 am encountering an issue where, after my friend likes the URL from the second query, the counter does not increase. Instead, the URL is removed from the list. What could be the problem here?

Answer №1

There are several issues with the implementation you are attempting:

  1. There are many questions regarding how to retrieve user ids of likes in specific situations. In short, if you have spent a significant amount of time searching for a solution without success, it may not be feasible to easily obtain these likes. Facebook does not readily provide user ids of individuals who have liked specific URLs, making it difficult to find a straightforward solution or comprehensive documentation on the matter. reference to a similar issue

  2. Let's consider some numbers. If you have 100 friends, and each of them has liked at least 100 URLs during their time on Facebook, your "query2" query would need to retrieve a set of 10,000 URLs, which is not practical for an FQL query. There are numerous discussions on this topic on Stack Overflow and even in Facebook's blog posts. It is essential to limit such queries to a manageable number that you have experimented with. This limit could range from a few hundred to thousands. In your scenario, it is advised to start with a limit of hundreds. You can achieve this by restricting query2 with "LIMIT 0,100" - test this and observe how the multyquery functions. Subsequently, you will need to "paginate" through the remaining results by iteratively adjusting the offset parameter. This means you will need to make 100 FQL requests to retrieve all the URLs that your friends have liked.

  3. What you are attempting to accomplish is not achievable in real time with just one query.

If your access token has the necessary user_likes and friends_likes permissions, you can access the url_like table.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Step-by-step guide on permanently assigning a value in Node.js

I recently started working with node js and I am facing an issue where I need to save an id in a global variable that is required in multiple functions. However, every time the server restarts, the variable gets emptied. Is there a way to persist this va ...

Calculate the total value of a certain field within an array when a specific condition is satisfied

I have two sets of data. I am looking to calculate the total time_spent for each course_id that appears in both set 1 and set 2. let set1 = [ { instructor_id: 7, course_id: 19, lesson_id: 1, time_spent: 0 }, { instructor_id: 7, course_id: 19, lesson_ ...

Is it possible to utilize the cv.imencode function in Opencv.js for exporting images in the webp format?

I'm looking to convert images from various extensions like png and jpg to webp format. I initially explored using OpenCV.js but was unable to locate the cv.imencode method for creating webp images. Can anyone confirm if this method is supported? If no ...

Is there a way to prevent a .load() function from executing if it has

On my webpage, I have implemented multiple buttons that each load a different partial "view" using the jQuery .load() method. While this functionality works well, I observed that repeatedly clicking on one specific button results in the partial view being ...

What are the steps to customize the index.html file within the build directory prior to serving it for each request using an Nginx server?

I need to make changes to the React index.html file on the server prior to delivering it to the browser upon request. My goal is to dynamically include open graph meta tags in the head based on the requested URL. Is there a way to accomplish this using N ...

Send data from input to controller without using $scope

I am encountering an issue with the code below. Typically, I would resolve this problem using $scope, but this time I have been asked to find a solution without utilizing $scope in the controller. I am implementing the "controller as" syntax for managing ...

Validating optional fields in React

My registration form includes the following fields: Name Email Password Confirm password Optional field Select role (student, professor, secretary) Here's what I'm trying to achieve: If I want to create a user with a student role, the optional ...

What is the best way to utilize Link for navigation in React with Material UI?

const pages = ['home', 'menu', 'reservation']; <Box sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}> {pages.map((page) => ( <Link component={Link} to='/'>Home</L ...

JavaScript obtain scroll position of a child element

I have a setup that looks something like the following: <div> <div id="scrollID" style="height:100px;"> content here </div> </div> <script> document.getElementById("myDIV").addEventListener("touchstart", m ...

Troubleshooting URL Problems with Node.js Search and Pagination

My results page has pagination set up and the routes are structured like this: app.get("/results",function(req,res){ query= select * from courses where // this part adds search parameters from req.query to the sql query// Object.keys(req.query.search).for ...

Using Javascript to delete a cookie that was created by an AJAX response

Within my Webapp (which is currently running at localhost/myApp/), I am utilizing an ajax call as shown below: $.ajax({ type: "GET", url: "http://localhost:8080/my.module/Login/login?user=abc&password=123", xhrFields: { withCredent ...

How to capture a specific part of a model using Autodesk Forge Viewer

I have a situation where I have 20 element Ids that I need to capture screenshots of in a specific size (400x400) like a detail view. The current viewer I am using has different dimensions, so I'm wondering if there is a way to achieve this and return ...

Conceal the div with ID "en" if the value matches $en

Looking for assistance with language settings on my page. I have a menu where I can select English, Croatian, or German. Below is the code to manage language changes: <?php class home_header_language { protected $_DBconn; ...

Navigating the From and To routes in Nuxt/Vue: A comprehensive guide

I am currently working on a Nuxt/Vue project. While inspecting in Dev Tools, I came across a From and To property. How can I access these properties within the Nuxt application? I have attempted to use this.$nuxt.$route, this.$nuxt.$router, and this.$rou ...

Is there a way to stop the execution of myFunc after it has been performed 5 times using clearInterval?

This code is designed to notify online shoppers that they need to choose a color from a dropdown menu before adding an item to their shopping cart. If no color is selected, the text will blink to alert them. How can I modify this code so that the blinking ...

Stuck on loading screen with Angular 2 Testing App

Currently working on creating a test app for Angular 2, but encountering an issue where my application is continuously stuck on the "Loading..." screen. Below are the various files involved: app.component.ts: import {Component} from '@angular/core& ...

The XMLHttpRequest function successfully logs data in the console, but does not return the data within the function itself

I find it puzzling that the console.log statement at the end of the code snippet displays the data as expected, while the return optiondata line does not. function populate_selectbox() { var ajaxRequest; try { // Opera 8.0+, Firefox, S ...

What is the best way to extract the value from a Material UI Slider for utilization?

I am looking to capture the value of the slider's onDragStop event and store it as a const so that I can use it in various parts of my code. However, I am unsure about how to properly declare my const sliderValue and update it. Any guidance on where a ...

Updates to object properties are not appearing in Vue component

I am facing an issue with a Vue component that has a single prop, which is an object. Despite changing a property in this object, it does not reflect the update in the Vue template. Below is a simplified version of the component: <template> <p ...

Animating the change in Slider value with Material-UI in React

Recently delving into React, I encountered my first challenge that has been consuming my time for hours. I'm working with a Slider component from Material-UI and seeking to animate the value changes. Currently, when clicking on a button, the slider i ...