Created
September 4, 2018 17:07
-
-
Save mattvv/375e45a623661d37f3e6062f15142ae8 to your computer and use it in GitHub Desktop.
Revisions
-
Matt Van renamed this gist
Sep 4, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Matt Van created this gist
Sep 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import { GraphRequest, GraphRequestManager } from 'react-native-fbsdk'; //Gets all your friends who have used the app, exploding facebook's caching. export const getFriends = async () => { try { let { pagedFriends, cursor } = await friendsRequest(); let allFriends = pagedFriends; while (pagedFriends.length > 0) { let request = await friendsRequest(cursor); pagedFriends = request.pagedFriends; cursor = request.cursor; allFriends = [...allFriends, ...pagedFriends]; } return allFriends; } catch (error) { return []; } }; const friendsRequest = startFrom => { const requestUrl = !startFrom ? `/me/friends` : `/me/friends?after=${startFrom}`; return new Promise((resolve, reject) => { const friendsRequest = new GraphRequest(requestUrl, null, (error, result) => { if (error) { reject(error); } else { const cursors = result.data.length > 0 ? result.paging.cursors.after : undefined; resolve({ pagedFriends: result.data, cursor: cursors }); } }); new GraphRequestManager().addRequest(friendsRequest).start(); }); };