Posts tagged with pagination

Im trying to get all the comments of the posts, im using the after and before things of the cursor in Facebook graph, but it does not give me all comments.

const fetchAllPostComments = async (postId: string, after: string | null = null, limit: number = 25): Promise<any[]> => {     const pageQuery = after ? `&after=${after}&limit=${limit}` : `&limit=${limit}`;     const response = await fetch(`${GRAPH_API_URL}/${postId}/comments?access_token=${PAGE_ACCESS_TOKEN}${pageQuery}`);     const data = await response.json();     let allComments = data.data || [];     if (data.paging && data.paging.cursors && data.paging.cursors.after) {         const nextComments = await fetchAllPostComments(postId, data.paging.cursors.after, limit);         allComments = allComments.concat(nextComments);     }     console.log(allComments);     return allComments; }; 

I'm using Meta Graph Api Explorer to test the Meta Ads API.

And the results look like this:

Request For First Page

When I add the after token into the request as a parameter, it doesn't return the token for the previous page:

Request For Second Page

here's the URL endpoint:

ads_archive?ad_reached_countries=['GE']&search_terms="A"&after= c2NyYXBpbmdfY3Vyc29yOk1UY3pNek0yTURRd01EbzRNakUyTnpZAMU9UTXpNVFl6T1RNPQZDZD