Note that there are some explanatory texts on larger screens.

plurals
  1. POBatching up, sending, and receiving a large number of Facebook Graph API calls
    primarykey
    data
    text
    <p>I'm trying to use the Graph API and the PHP+JS SDK to get a person's friend list, and then go out and get the mutual friends for everyone on the friend list. I can get the friend list easy-peasy as it's just one simple API call. However, the problem arises when trying to get all the mutual friends. Assuming a person has 500 friends, that's 501 different API calls to run the app once, which is way too many. </p> <p>Fine.</p> <p>Next idea. Batch up all those API calls and turn 501 into 25. It seemed like a good idea, and that's what I did. Unfortunately, it didn't work. Here's what my code:</p> <p><strong>KK NVM, I FIXED IT (MOSTLY). IT STILL RUNS REALLY SLOW THOUGH. HERE'S THE NEW CODE:</strong></p> <pre><code>$userFriends = $facebook-&gt;api('/me/friends', 'GET'); $queries = array(); $mutual_friends = array(); foreach ($userFriends[data] as $v1) { $queries[] = array('method' =&gt; 'GET', 'relative_url' =&gt; '/me/mutualfriends/'.$v1[id]); if (count($queries)==20){ $batchResponse = $facebook-&gt;api('?batch='.json_encode($queries), 'POST'); foreach (range(0,count($queries)-1) as $n) { $mutual_friend[] = json_decode($batchResponse[$n]['body'], true); } $queries = array(); } $batchResponse = $facebook-&gt;api('?batch='.json_encode($queries), 'POST'); foreach (range(0,count($queries)-1) as $n) { $mutual_friend[] = json_decode($batchResponse[$n]['body'], true); } } </code></pre> <p>I have the sneaking suspicion that you're not really supposed to batch API calls like this, but I could be wrong. Also, I've read that FQL is actually a better, preferred method for getting this kind/amount of information, but that would mean that I'd need access to the other people's friend list as well. </p> <p>The only other solution I can think of would be to throttle the calls, but I don't really want to do that cause I don't want the app to run slowly or have a significant wait period. </p> <p>Is what I'm trying to do even possible? Am I going about it in the wrong way? Any input or expertise would be greatly appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload