MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / fetchAllFriends_

Function fetchAllFriends_

scripts/fb_GLOBAL.js:182–214  ·  view source on GitHub ↗
(access_token, progressCallback)

Source from the content-addressed store, hash-verified

180 );
181}
182export async function fetchAllFriends_(access_token, progressCallback) {
183 let friends = [];
184 let total = 0;
185 let limit = 25;
186 let after = null;
187
188 while (true) {
189 try {
190 const res = await fetch(
191 `https://graph.facebook.com/v19.0/me?fields=friends` +
192 `&access_token=${access_token}&pretty=0&limit=${limit}` +
193 (after ? `&after=${after}` : "")
194 );
195 const json = await res.json();
196 const { data, paging, summary } = json.friends;
197 total = summary.total_count || total;
198 friends = friends.concat(data);
199
200 progressCallback?.({
201 data: friends,
202 loaded: friends.length,
203 total,
204 });
205
206 if (!paging?.cursors?.after || paging.cursors.after === after) break;
207 after = paging.cursors.after;
208 } catch (e) {
209 console.error(e);
210 break;
211 }
212 }
213 return friends;
214}
215export async function fetchAddedFriends(uid, fb_dtsg, cursor) {
216 let variables = JSON.stringify({
217 count: 8,

Callers

nothing calls this directly

Calls 2

concatMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected