Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9066175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:40:50+00:00 2026-06-16T16:40:50+00:00

I’m workin on an app that would award its users points for each of

  • 0

I’m workin on an app that would award its users points for each of their friends liking my page.

I need a way to check how many of user’s friends like my page. I developed this piece of code to check each my friends for liking a particular page:

    $friends = $facebook->api('/me/friends'); //list my friends
    $time_start = microtime(true);
    echo "<pre>";
    $i = 0; //counter of likes
    $b = 0; //counter of request in single batch API request
    $batch_max = 50 // facebook allows max 50 requests in single batch API call
    $page_id = '187941397895831'; //example page ID, i'm checking how many of my    friends like this page
    $batch = array(); //array used for creating batch API request
    $data = array(); //array collecting all API requests results
    foreach ($friends['data'] as $friend) {
        $req = array(
            'method' => 'GET',
            'relative_url' => '/'.$friend['id'].'/likes'
        );
        $batch[] = json_encode($req);
        $b++;
        if ($b == 50) {
            $params = array(
                'batch' => '[' . implode(',',$batch) . ']'
            );
            $data[] = $facebook->api('/', 'POST', $params);
            $b = 0;
            $batch = array();
        }
    }
    $params = array(
        'batch' => '[' . implode(',',$batch) . ']'
    );
    $data[] = $facebook->api('/', 'POST', $params);
    foreach ($data as $data_set) { //iterate through results of each api request
        foreach ($data_set as $friend_likes) { //iterate through data of particular friend
            $likes_array = json_decode($friend_likes['body'], true);
            foreach ($likes_array['data'] as $single_like) { //iterate through all likes of a single friend
                if ($single_like['id'] == $page_id) { //if page id found in user's likes increase counter
                    $i++;
                }
            }
        }
    }
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    echo $time."\n";
    echo $i;
    echo "</pre>";
    exit;

In final version I will not be checking my friends but friends of each of my users. My code executes in 14 seconds, if I had to iterate through, let’s say, 100 users it’d be 1400 seconds, which is waaaay to long. Is there better way to do that? I’m newbie to facebook API, so I could miss something obvious 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:40:51+00:00Added an answer on June 16, 2026 at 4:40 pm

    Ok, so here’s the working piece of code. You need to know access token for each of users being checked. It executes in ~0.6 seconds instead of 14 seconds for previous code.

    $queryResults = array();
    $facebook->setAccessToken($user->getAccessToken());
    $fql = "SELECT '' FROM page_fan WHERE page_id = 'xxxxxxxxxxxx' AND uid IN (SELECT uid2 FROM friend WHERE uid1 = '".$user->getFbId()."')";
    $fql = urlencode($fql);
    
    try {
        $queryResults = $facebook->api(
            '/fql?q='.$fql
        );
    } catch (FacebookApiException $e) {
        $log->setMessage(print_r($e,true));
        $logMapper->save($log);
    }
    
    if (!empty($queryResults)) {
        $user->setPoints(count($queryResults['data']));
        $usersMapper->save($user);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.