Note that there are some explanatory texts on larger screens.

plurals
  1. POfacebook batch/fql friendlists a friend is member of
    text
    copied!<p>I'm creating a javascript facebook app to have an overview of my friendlists. Actually I can retrieve my (logged in user = me) friendlists, when I click a friendlist I see all my friends in that list.</p> <p>When I want now is, when I click a list, I want to see the friends belonging to that list, and a comma separated lists my friend is member of.</p> <p>For example in the list <strong>"Best"</strong> I have 3 friends: <strong>Athos, Portos, Aramis</strong>. But they are also in other lists. So in my app I'd like to get something like this:</p> <ul> <li><strong>Athos</strong>: Best, Family, Close Friends, VIP</li> <li><strong>Portos</strong>: Best, VIP</li> <li><strong>Aramis</strong>: Best, Close Friends, Party Animals</li> </ul> <p>I tried with the FQL multiquery, but it seems impossible to get what I want.</p> <p>So I think I should use a Batch request, but since I don't have a lot of experience using batches here I am asking your help.</p> <p>So here the FQL query I use to get friends belonging to the list. I need this, because I want to manage friends beginning from a list:</p> <pre class="lang-js prettyprint-override"><code>var listID = 123;//just enter a listID var friendsInList = 'SELECT uid,username,profile_url,first_name,last_name,pic_square FROM user WHERE uid IN (SELECT uid FROM friendlist_member WHERE flid =' + listID +')'; </code></pre> <p>Now I don't know how to proceed in a clean and efficient way. I have a working but inefficient solution:</p> <pre class="lang-js prettyprint-override"><code>//[...]FB.api call to get a response object with all my friends using the friendsInList query above for (var i = 0; i &lt; response.length; i++) { friendID = response[i].uid; //call FB.api with the following query: var friendListMemberships = 'SELECT uid, flid, name FROM friendlist_member WHERE flid IN (SELECT flid FROM friendlist WHERE owner=me()) AND uid IN (select uid FROM friendlist WHERE flid =' + friendID; } </code></pre> <p>the above solution works but is highly inefficient as I send a FB.api request for each friend, very slow for big lists... thus I'd like a pro user to help me putting this in a <a href="https://developers.facebook.com/docs/reference/ads-api/batch-requests/" rel="nofollow">batch</a> (a batch can have maximum 50 requests, thus I'd like to send just 1-2 requests and get back all what I need).</p> <p>I know how to write a batch, here I put the structure of my code, if it can help you completing it with the second query:</p> <pre class="lang-js prettyprint-override"><code>var listID = _listID; var _queryFriendsInList = 'SELECT uid,username,profile_url,first_name,last_name,pic_square FROM user WHERE uid IN (SELECT uid FROM friendlist_member WHERE flid =' + listID + ')'; var queryFriendsInList = _queryFriendsInList.replace(" ", "+"); var _queryFriendListMemberships = 'I have no idea what kind of query I can write here to get the lists my friends from queryFriendsInList are member of'; var queryFriendListMemberships = _queryFriendListMemberships.replace(" ", "+"); var searchArgs = { access_token: FB.getAuthResponse().access_token, batch: [] }; searchArgs.batch.push({ 'method': 'GET', 'name': 'friendsInList', 'relative_url': 'method/fql.query?query=' + queryFriendsInList, 'omit_response_on_success': false }); //here is where I need help searchArgs.batch.push({ 'method': 'GET', 'name': 'friendlistMememberships', 'relative_url': 'method/fql.query?query=' + queryFriendListMemberships, 'omit_response_on_success': false }); FB.api("/", "POST", searchArgs, function (response) { //console.log("log"); } ); </code></pre> <p>I hope the question and code samples are clear enough. Thank you for helping!</p>
 

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